How to use an array?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: How to use an array?
He said with a deadpan...
-
- Posts: 29
- Joined: Sat Apr 10, 2021 6:56 pm
Re: How to use an array?
Lots of great tips here and sample code snippets to learn from. Thanks everyone!
Gary E Chike DMD
"Experience is what you get when you don't get what you want"
"Experience is what you get when you don't get what you want"
-
- Posts: 90
- Joined: Sun Feb 15, 2015 2:51 pm
Re: How to use an array?
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.
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.
In the end I chose an intermediate solution, which is this:
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.
Re: How to use an array?
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'?
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'?
-
- Posts: 90
- Joined: Sun Feb 15, 2015 2:51 pm
Re: How to use an array?
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.
The question is how I create a string in the loop that concedes all the letters of each word, after encrypted them with the numbers and special characters.
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.
The question is how I create a string in the loop that concedes all the letters of each word, after encrypted them with the numbers and special characters.
I mean, ie making sure that "abcde" becomes "1*2%3&4§5-".
Re: How to use an array?
if you want to encrypt, why not use the encrypt functions? I'm not sure how interspersing non-textual characters helps?
if the 'encryption' is to be used as a string, one would normally do a base64encode of the encrypted data.
Check the Dictionary for Encrypt, Decrypt and base64encode/decode - maybe that's what you need?
For example, to encrypt a string and then encode as text:
to do the opposite:
You can set breakpoints and step through the code if you want to see the intermediary values...
if the 'encryption' is to be used as a string, one would normally do a base64encode of the encrypted data.
Check the Dictionary for Encrypt, Decrypt and base64encode/decode - maybe that's what you need?
For example, to encrypt a string and then encode as text:
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 encryptAndEncodeMyString
Code: 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 decryptAndDecodeMyString
-
- Posts: 90
- Joined: Sun Feb 15, 2015 2:51 pm
Re: How to use an array?
The fact is that I am taking advantage of this thing that came to me to resolve the problems meeting in doing it, language problems. In other words it is a way to learn how to use LiveCode to do what I want to do.
I thank you very much for the inspiration you gave me, I'll keep it in mind if I won't be able to do as I want.
Is there anything I can do to create the string in the cycle as I illustrated?
I thank you very much for the inspiration you gave me, I'll keep it in mind if I won't be able to do as I want.
Is there anything I can do to create the string in the cycle as I illustrated?
Re: How to use an array?
Well if you don’t care in what sequence you want your non-textual chars you could use random to pick one of these and then just build a string where you use the number equivalent for each letter and add a random non-text after each.
If you can’t figure out the code yourself post what you done and people will help
If you can’t figure out the code yourself post what you done and people will help
-
- Posts: 90
- Joined: Sun Feb 15, 2015 2:51 pm
Re: How to use an array?
in realtà l'ho pubblicato, se hai fatto caso ai post a cui tu hai risposto.
Comunque eccolo di nuovo
Comunque eccolo di nuovo
AlessioForconi wrote: ↑Thu Apr 14, 2022 3:50 pmI 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.
Re: How to use an array?
Εάν πρόσεχες αυτά που σου έχουνε πει όλοι, θα είχες ήδη βρει τη λύση...AlessioForconi wrote: ↑Thu Apr 14, 2022 9:20 pmin realtà l'ho pubblicato, se hai fatto caso ai post a cui tu hai risposto.
Comunque eccolo di nuovo
Το δικό σου το πρόγραμμα έχει πολλά λάθη... πως γίνεται να έχεις 8 μεταβλητες σε 15 γραμμες κωδικου? Και που βγηκε η τελευταία μεταβλητή που προσπαθεις να επιστρεψεις? Φυσικα δεν δουλεψει γιατι δεν το εχεις δωσει καμμια αξια στο ret... μαθαινεις μονο οταν προσπαθησεις να λυσεις το προβληματα μονος σου, αλλα προφανως δεν αντιλαμβανεσαι αυτα που σου λενε.
Αφού δεν τα καταφέρνεις, θα σου το εξηγήσω με ένα απλό παράδειγμα:
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 skEncode
Code: Select all
on mouseUp pButtonNumber
put skEncode(field "source") into field "destination"
end mouseUp