Re: How to use an array?
Posted: Fri Mar 25, 2022 5:09 pm
He said with a deadpan... 
Questions and answers about the LiveCode platform.
https://forums.livecode.com/
Code: Select all
on mouseUp pButtonNumber
put the text of field "txtSeeds" into seed
put 1 into counter
repeat for each words temp in seed
put Encode (temp, counter) into encodedstring
put encodedstring into field "txtNumbers"
add 1 to counter
end repeat
end mouseUp
function Encode pWords, pCounter
put pWords into tWord
put "/*-+=!£$%&/()=?^*§#@" into specialchar
put "abcdefghijklmnopqrstuvwxyz" into pool
repeat for each char item in tWord
add 1 to i
put char i of tWord into lettera
if lettera is in pool then put offset(lettera, pool) & any char of specialchar into numbers
put numbers into encodedchar
put encodedchar into pippo
answer lettera && "-->" && numbers
end repeat
return ret
end Encode
The special characters do not have much importance for the purposes of what I want to do, they are just an addition that I do for encryption.stam wrote: Thu Apr 14, 2022 5:25 pm Not sure i understand what you're trying to do...?
I get that you want to represent letters as numbers - and that's been discussed above.
I don't understand the role of the 'special chars'?
Code: Select all
function encryptAndEncodeMyString pString
local tEncrypted, tEncoded
encrypt pString using "aes-256-cbc" with password "@&^2fy" // put your own choice of password here
put it into tEncrypted
put base64Encode(tEncrypted) into tEncoded
return tEncoded
end encryptAndEncodeMyStringCode: Select all
function decryptAndDecodeMyString pString
local tDecrypted, tDecoded
put base64Decode(pString) into tDecoded
decrypt tDecoded using "aes-256-cbc" with password "@&^2fy" // obviously same password as above
put it into tDecrypted
return tDecrypted
end decryptAndDecodeMyStringAlessioForconi wrote: Thu Apr 14, 2022 3:50 pm I do my apologies for the delay with which I answer, fault of a difficult time with the Covid.
In the end I chose an intermediate solution, which is this:The function code is a bit dirty, I will clean up.Code: Select all
on mouseUp pButtonNumber put the text of field "txtSeeds" into seed put 1 into counter repeat for each words temp in seed put Encode (temp, counter) into encodedstring put encodedstring into field "txtNumbers" add 1 to counter end repeat end mouseUp function Encode pWords, pCounter put pWords into tWord put "/*-+=!£$%&/()=?^*§#@" into specialchar put "abcdefghijklmnopqrstuvwxyz" into pool repeat for each char item in tWord add 1 to i put char i of tWord into lettera if lettera is in pool then put offset(lettera, pool) & any char of specialchar into numbers put numbers into encodedchar put encodedchar into pippo answer lettera && "-->" && numbers end repeat return ret end Encode
Now, however, I find myself in front of another difficulty that should be a trivial solution but from which I can't go out.
The goal is to return to the function a string composed of all the elves of each speaks after coding it with the numbers and special characters but I can't understand how to do it.
To better say the function should return every word, such as "ABCDE" as "1 * 2% 3 & 4§5-" but I can't create the string to be restored to the function.
I thank you for the suggestions you want to give me.
Εάν πρόσεχες αυτά που σου έχουνε πει όλοι, θα είχες ήδη βρει τη λύση...AlessioForconi wrote: Thu Apr 14, 2022 9:20 pm in realtà l'ho pubblicato, se hai fatto caso ai post a cui tu hai risposto.
Comunque eccolo di nuovo
Code: Select all
function skEncode pText
constant kSpecialChars = "/*-+=!£$%&/()=?^*§#@"
local tText
repeat for each char tChar in pText
if tChar = " " then // maintain spaces in text
put " " after tText
else if nativeCharToNum(toUpper(tChar)) - 64 > 0 then
put nativeCharToNum(toUpper(tChar)) - 64 & any char of kSpecialChars after tText
end if
end repeat
return tText
end skEncodeCode: Select all
on mouseUp pButtonNumber
put skEncode(field "source") into field "destination"
end mouseUp