A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: [FlashMXPro2004/AS2.0] Password system help

  1. #1
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650

    [FlashMXPro2004/AS2.0] Password system help

    Hi fellow FKers

    There is this thing I've always wanted to know how to do, and stll to this day I don't know how to do it. So I thought it's about time I asked you experienced dudes how this can be done.

    What I would like to know how to do is manipulating letters in sentences/lines/words. As I know a bit of arrays, I thought maybe among those thingies you could do with arrays you maybe could also manipulate the letters of each word. An example: ["one", "two", "three"...]. I know how to manipulate the words, but couldn't find a way to manipulate ie the "n" in "one".

    All I need to know is:

    How to encrypt a string, ie ABC123 to something random, like maybe the next letter/number in the string... so ABC123 becomes BCD234, and then also decrypt it back. It would be so fun for me if I knew how this could be done.

    The user will recieve a password string with all the info in it, for him to paste into a text field and pressing enter to continue where he left off. But I don't want him to see the real letters and numbers... that's why I want to know how to maniuplate parts of a string...

    I hope you understand what I mean. If not, just ask and I'll reply

    Thanks for any help.
    Last edited by Ironclaw; 09-14-2009 at 06:20 PM.

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    You can split string into array containing single letters

    arr = str.split("");

    Now you loop through the array and change the letters using whatever algorithm. Once they are all changed, put new string back together.

    How to change each letter is really up to you. Do you want to make sure the string is not changed by user? Then you need to add some sort of checksum or crc too.

    Simple explanation of encryption:
    http://computer.howstuffworks.com/encryption.htm

  3. #3
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Thanks for the reply, and this password system doesn't have to be so secure, so no crc and the like is needed.

    Anyway, I've read up on .split and I just can't figure out how to do what I want.

    If it's not too much trouble, could you or someone else just type a code to make

    FlashKitIsThePlaceToBe

    into something new, trace it, then turn it back to its original?

    To turn it back into the original is probably not so easy as the thing to make the above example into something else need to keep the structure for how it changed it... meh, I almost don't understand what I'm typing...

    Ok, another example:

    When the user decides to stop playing, he will get a code displayed, an example for that could could be:

    50003612200300

    5000=score
    3=life
    6=stage
    12=map
    200=x coords
    300=y coords

    So all I need is to change those numbers to whatever, display the new code to the user, and whenever he feels like going back to where he left off, he just paste it in a text field and click enter... but then flash would need to know how to change it back... so I need a system... which I explained in my first post... taking each number or letter and just move it to the next one... so 5000 would be 6111 (I know they could easily change the new code and get alot of health and cheat, but it's np, I got ideas, trust me).

    All I can do is to make Joe, split it into an array, then change ie the first letter to M, making Moe, then join the letters back to a word without spaces. I just can't figure out a way to cycle through the string, and change all the characters. Can't come up with a clever way to do this.

    Code:
    myString = "Joe";
    var my_array:Array = myString.split("");
    my_array[0] = "M";
    trace(my_array);
    trace(my_array.join(""));
    So, if it's not too much to ask, can I have an example of what I would like to accomplish? Or just some hints? The "arr = str.split("")" is enough for me to figure out how to change them all to a new character and I can't figure this out.
    Last edited by Ironclaw; 09-16-2009 at 04:49 PM.

  4. #4
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Maybe something like this:
    Code:
    var myString = "Joe";
    myString = myString.toUpperCase();
    var letString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    var my_array:Array = myString.split("");
    for(var n = 0; n < my_array.length; n++){
    	var curLet = my_array[n];
    	my_array[n] = letString.charAt(letString.length - letString.indexOf(curLet));
    }
    //traces "1W6"
    trace(my_array.join(""));
    Its fairly simple, just replace each char in original string with other char from the string of letters counting position from the end. A will be 9, B becomes 8 etc.

    Its easy because you use the same code to get original sting back, replace myString with value "1W6" and it will trace "JOE".

    I only used uppercase letters thats why original string is converted into uppercase.

  5. #5
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Wow! thanks, lovely code and works for those characters. I could need it to work with all characters so I tried adding all chars I could think of, but have a problem.

    I use a html link as an example:

    I take "http://img201.imageshack.us/img201/5...nandrobin6.jpg" encrypt it and get "vjjn5--uqxacb(uqxzkvÄs(ik-uqxacb-:ö~:-ÖjqppÅloÖup-(tnx" which I paste in the second var myString = "". But don't get the correct result and can't quite figure out why. This is the result when converting it back: "http://imfÄÖ.imfdshCk.us/imfÄÖ/5...mnnDroBin/.jpf"

    Here's a picture instead, easier to read as links gets shortened:


    I noticed that with the original char set and if I had "joe", the "j" wouldn't show, so had to add lower case letters aswell.... wonder why the string doesn't convert back correctly even though I've included all the characters.

    Code:
    var myString = "http://img201.imageshack.us/img201/5985/batmanandrobin6.jpg";
    myString = myString.toUpperCase();
    var letString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#¤%&/()=?`´@£$€{[]}\^*,.-><|åäö~+-:;_abcdefghijklmnopqrstuvxyzÅÄÖ";
    var my_array:Array = myString.split("");
    for (var n = 0; n<my_array.length; n++) {
    	var curLet = my_array[n];
    	my_array[n] = letString.charAt(letString.length-letString.indexOf(curLet));
    }
    trace(my_array.join(""));
    var myString = "vjjn5--uqxacb(uqxzkvÄs(ik-uqxacb-:ö~:-ÖjqppÅloÖup-(tnx";
    myString = myString.toUpperCase();
    var letString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#¤%&/()=?`´@£$€{[]}\^*,.-><|åäö~+-:;_abcdefghijklmnopqrstuvxyzÅÄÖ";
    var my_array:Array = myString.split("");
    for (var n = 0; n<my_array.length; n++) {
    	var curLet = my_array[n];
    	my_array[n] = letString.charAt(letString.length-letString.indexOf(curLet));
    }
    trace(my_array.join(""));
    Last edited by Ironclaw; 09-17-2009 at 11:05 AM.

  6. #6
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    i did a similiar project (AS2) recently, please take a look at the results

    http://www.jackleaman.co.uk/test/str...ars_ascii.html

  7. #7
    Senior Member
    Join Date
    Sep 2008
    Posts
    121
    Quote Originally Posted by a_modified_dog View Post
    i did a similiar project (AS2) recently, please take a look at the results

    http://www.jackleaman.co.uk/test/str...ars_ascii.html
    Hi, this looks really interesting, but I can't get it to work.

    I have Macromedia Flash Professional 8, I copy and paste your code on frame 1 in on the timeline, then add 3 text fields, the first is of course set to input text, I give them their names, and add buttons and name them btn1 and btn2.... but when I then test it and type some text in the top field and click a button, flash just freeze.... :/. Could you tell me what I might do wrong, or make me a fla?

    Would be much appreciated

  8. #8
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    As I can't get the previous stuff to 100% work, it leaves me only with a_modified_dog's example which does exactly what I need, but I too can't get it to work and also would much appreciate a fla

  9. #9
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    The only problem with a modified dog's (sorry, a_modified_dog's) example is that it uses the same substitute letter for the same letter...as in an A will always be encoded to a $ let's say.
    I would try to base the encoding on let's say a random seed (which can be mixed into the encoded string), and based on the previous letter. Something where the results are always unpredictable, but can still be decoded back.

    I can make an example, since this even sounds a bit interesting!

    P.
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  10. #10
    Senior Member
    Join Date
    Sep 2008
    Posts
    121
    Yes, please make a downloadable example

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center