How to use an array?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to use an array?

Post by Klaus » Fri Mar 25, 2022 5:09 pm

He said with a deadpan... :D

garmeister
Posts: 29
Joined: Sat Apr 10, 2021 6:56 pm

Re: How to use an array?

Post by garmeister » Sat Mar 26, 2022 5:50 am

Lots of great tips here and sample code snippets to learn from. Thanks everyone! :D
Gary E Chike DMD
"Experience is what you get when you don't get what you want"

AlessioForconi
Posts: 90
Joined: Sun Feb 15, 2015 2:51 pm

Re: How to use an array?

Post by AlessioForconi » 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:

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 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.
Attachments
Screenshot_428.png

stam
Posts: 2636
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to use an array?

Post by stam » 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'?

AlessioForconi
Posts: 90
Joined: Sun Feb 15, 2015 2:51 pm

Re: How to use an array?

Post by AlessioForconi » Thu Apr 14, 2022 5:34 pm

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'?
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-".

stam
Posts: 2636
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to use an array?

Post by stam » Thu Apr 14, 2022 6:19 pm

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:

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
to do the opposite:

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
You can set breakpoints and step through the code if you want to see the intermediary values...

AlessioForconi
Posts: 90
Joined: Sun Feb 15, 2015 2:51 pm

Re: How to use an array?

Post by AlessioForconi » Thu Apr 14, 2022 8:51 pm

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?

stam
Posts: 2636
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to use an array?

Post by stam » Thu Apr 14, 2022 9:15 pm

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 :)

AlessioForconi
Posts: 90
Joined: Sun Feb 15, 2015 2:51 pm

Re: How to use an array?

Post by AlessioForconi » 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
AlessioForconi 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:

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 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.

stam
Posts: 2636
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to use an array?

Post by stam » Fri Apr 15, 2022 1:48 am

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
Εάν πρόσεχες αυτά που σου έχουνε πει όλοι, θα είχες ήδη βρει τη λύση...
Το δικό σου το πρόγραμμα έχει πολλά λάθη... πως γίνεται να έχεις 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
Εάν έχεις ένα πεδίο "source" και ενα "destination" βαλε και αυτο σε ενα κουμπι...

Code: Select all

on mouseUp pButtonNumber
     put skEncode(field "source") into field "destination"
end mouseUp

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”