Translating letters too numbers

i want to know if there is a way to translate letters to numbers look at the example.

a = 6
b = 11
c = 2

abc translated would be…
6112

but i wouldnt know how to make the AS convert the 6112 to make ABC…
any suggestions?

yes, but it can be a function a clipevent or is this executed from a button, that’s important.

if you tell me what exactly do u wanna achive, and why you wanna translate the numbers to letter and vice versa. maybe i can give you another solution!

huh? i dont understand it. i want to achieve a program for secret spies :slight_smile: … LOL. or if i can do it by numbers than maybe by lettters?
a = k
b = o
c = z

koz = abc

can you give me some examples of AS to make all “a’s” in a text the letter k?
like if
txt.letterA = R [translate
txt.LetterR = A [re-translate

oh by a BUTTON


a = 3; \\  here you enter your values
b = 4;
c = 5;
 \\ shoul have a button named "submit" and a input text field with var name "inputed"
 _root.submit.onPress = function () {
	 lowered = inputed.toLowerCase();
	 resultcode = "";
	 for (i=0; i < inputed.length;i++) {
		 resultcode += eval (lowered.charAt(i));
		 }
		 result.text = resultcode;
	 }
 

Enjoy :wink:

hmm i dont fully understand the concept. what do i put in result code? and im guessing i should have a txt box named resultcode?

I don’t think so. Since there are 26 letters in the alphabet, you’ll have number equivanlents that have more than 2 figures, so you need to put some sort of separator between the letters:

a = 3; \\  here you enter your values
b = 4;
c = 5;
 \\ shoul have a button named "submit" and a input text field with var name "inputed"
 _root.submit.onPress = function () {
	 lowered = inputed.toLowerCase();
	 resultcode = "";
	 for (i=0; i < inputed.length;i++) {
		 resultcode += eval (lowered.charAt(i)) + "_";
		 }
		 result.text = resultcode;
	 }
}

That way you can split the resulting string using the separator “_” and retrieve the original words very easily.

for result.text = resultcode;
I used a dynamic text box named result. Resultcode was a variable set to “” empty… each time you submit another string to it, otherwise it would have attached the result at the end each time it ran, creating a longer and longer string.
And as Ilyas said you may be needing some kind of separator if you use numbers.
Or use other letters instead, as in - reorder the alphabet.

alright i think i got it from here guys… thanks for your help!

oh wait, it works perfectly when i do this,

a="elp"
b="dra"
c=“lar”

and etc. but when i translate it back it will make it one long word with no spaces, so if i put a space into the inputted box and translate to result there will be no spaces. how would i make it so that the spaces in the input will be recorded into the result box.?

and how would i translate the code? i have,

elp="a"
dra="b"
lar="c"
pro="d"
der="e"
got="f"
hay="g"
far="h"
son="i"
red="j"
med="k"
yet="l"
hit="m"
rip="n"
jan="o"
gop="p"
wop="q"
win="r"
med="s"
met="t"
car="u"
rea="v"
dre="w"
ber="x"
vab="y"
xac="z"
 //should have a button named "submit" and a input text field with var name "inputed"
 _root.submit.onPress = function () {
	 lowered = inputed.toLowerCase();
	 resultcode = "";
	 for (i=0; i < inputed.length;i++) {
		 resultcode += eval (lowered.charAt(i));
		 }
		 result.text = resultcode;
	 }

but that doesnt seem to work. aand i cant put quotes around the dre or ber because it detects an error…

well when i try to translate elp, i get the translation of E.L.P instaed of the word. i would get deryetgop for elp. how do imake it so when i type in elp, i get A? or maybe would it be more logical to make the a = elp. instead of a=elp?

more logical to make the a = elp. instead of a=elp?

Huh :)???
charAt(i) returns only one character.
you should use substr instead.
If nobody replyes … later when I have time I will write something.

i cant use 3 letters? i really want to use more than 3 letters. i can translate all the a, b, c into the 3 lette rwords but i cant change them back…

and theres another problem, not as big but when i translate it makes strange numbers that replace the letter heres a .swf to test it out

http://mdjstudios.freeunixhost.com/secretcode.html

ok dokey…
this will make your button translate first, then decrypt on pressing it again via the variable from1to3. if you want separate buttons extract the code from the if/else statement :wink:

der="e"
got="f"
hay="g"
e = "der"
f = "got"
g = "hay"
 \\ shoul have a button named "submit" and a input text field with var name "inputed"
 _root.submit.onPress = function () {
    if(from1to3 == 1){
	 lowered = inputed.toLowerCase()
	 resultcode = ""
	 for (i=0; i < inputed.length;i+=3) {
		resultcode += eval (lowered.substring(i,i+3)) //wer 3 is the length of your replacement code words
	}
        from1to3 = 0
	result.text = resultcode
	}
    }
    else{
	lowered = inputed.toLowerCase()
	resultcode = ""
	for (i=0; i < inputed.length;i++) {
		resultcode += eval (lowered.charAt(i))
	}
	result.text = resultcode
}

note i put the decryption script in first and the encryption script in the else statement…

Prophet.

EDIT:- on your .swf all i can find is that when you type “/” (without quotes) you get _level0 come up… easily remedied by putting in a code encryption equivalent (or whatever you want to call it) for the / character… also, you might want to add one in for space as well otherwise if you code it and then decode it it will all be one huge word…

I’m really not very skilled with flash actionscript, usualy write scripts with the AS dictionary near close :). And now again I’m at home and don’t have the flash installed.
but let’s try something
You can use 3 letters but you’ll have to use substr instead of charAt.

_root.submit.onPress = function () {
	 lowered = inputed.toLowerCase();
	 resultcode = "";
	 for (i=0; i < inputed.length;i+=3) {
		 resultcode += eval (lowered.substr(i,3));//will extract 3 characters beggining with the "i"th one
		 }
		 result.text = resultcode;
	 }

You’ll have problems with spaces though.
Later Edit: See if it works … hope i Solved the spaces problem.

_root.submit.onPress = function () {
	 lowered = inputed.toLowerCase();
	 resultcode = "";
	 for (i=0; i < inputed.length;i+=3) {
		while (lowered.charAt(i)==" "){
                             i++;
                             resultcode += " "; \	he space isn't translated
                              }
                        resultcode += eval (lowered.substr(i,3));//will extract 3 characters beggining with the "i"th one and evaluate them as variables name.
		 }
		 result.text = resultcode;
	 }

lol looks like i just beat u to it :wink:

just thought though, you cant name a variable a space… lol hope u did solve the space problem! :wink:

Prophet.

EDIT:- that should work fine… although you should use an IF statement instead… otherwise you will get a loop error as the while loop will loop all the time its condition is true…

i really dont understand what you guys are saying so im going to post the .fla. im just really confused at the moment…

the fla is in the zip…