Tuesday, November 16, 2010

How do i make a Language Translator on anytype of language, C++, VB, Java, Etc.?

I need to make a translator to translate a cipher laguage me and my freind created, how do i make a translator??How do i make a Language Translator on anytype of language, C++, VB, Java, Etc.?
You have made a cipher language with what they call bindings for each letter of the alphabet.



Let's take an example for the old Ceasar cipher. This cipher was created by Julius ceasar and is pretty basic. It just moves the alphabet a certain amount of numbers to the left. So let's say the number it moves is 2.



If you type in C in the code, it would be translated as an A. A being 2 letter behind C, or A + 2 = C, or C - 2 = A.



Hopefully you get that, because I will work for that example.



So if you were to implement the Ceasar cipher, you would create a list, or array of the alphabet.



static char ALPHABET[] = {'A', 'B', 'C', 'D', etc};



Then you would get the code you want to decipher. So just say it said something like ';FCJJM UNPJB'; which in English would be ';HELLO WORLD';



So, you would go through the string ';FCJJM UNPJB'; changing every letter to the letter it should be.

In Java you would do something like this.

char deciphered = word.toCharArray();

for (int i = 0; i %26lt; word.length(); i++) // where word is the string

int charValue = (int) deciphered[i] - 97; // minus 97 as the ASCII code for A is 97.

Now, you would want to find out if the charValue is below 2. If it is, you would add 26 - 2 to the charvalue to get the next letter.

For example, A would be 0, and you want to get 24, which is Y.

B would be 1, and you would get 25, which is Z.

If the charValue is 2 or above, you would just minus 2 from the charValue. C (2) would give you A (0).

if (charValue %26lt; 2)

charValue = charValue + 26 - 2;

else

charValue = charValue - 2;



Then change the char in deciphered.

deciphered[i] = ALPHABET[charValue];

} // end for loop



Ok, to get back to your example. if your code does not change, and you know that A refers to an S always, and B refers to an F always, you could do something like this.



Create an array of the alphabet as above.

Create another array of the letters that are for the letters of the alphabet.

static char CODE = {'S', 'F', etc};

The do the same for loop as above, but this time instead of changing the value of the charValue to -2 etc, do this.

deciphered[i] = CODE[ ALPHABET[ charValue ]];



Hope that is understandable. If not click on my profile and email me and I can explain more.How do i make a Language Translator on anytype of language, C++, VB, Java, Etc.?
That may be extremely hard. You have to find the patterns in the differences between the languages. Also, it is partially impossible b/c the different languages have different features, which means that there are things in Java that is not present in C++, so things may be lost.

No comments:

Post a Comment