Secret Language Converter

Yodenheim

Member
Joined
Nov 10, 2011
Messages
5
Programming Experience
1-3
Hello, I am new, but not to VB. I am creating a secret language out of numbers, I am making a VB translator to translate back and forth between languages. No it's not binary, and not, it's not A=1 B=2, etc. Its in a 2nd and 3rd flip flop. The first, and every 3rd one after, have there correct numeric ID.

a=1
b=3
c=2

d=4
e=6
f=5

But, I have no idea how to convert letters into numbers and visa versa.

How can I do this?
 
One relatively simple option, at least for converting from numbers to characters, would be to create an array. The first element would be "a", the second "c" and the third "b" and so on. Going from characters to numbers is slightly more complicated, you could loop through an array until you find the character, and take the index you're up to. Or you could grab a number code (such as the ASCII code of that character) and use that as the key for a second array. There are many ways to solve the same problem.
 
You need some sort of lookup table. You can use a single array, as suggested Ehsanit. I'd suggest that the most efficient option in use would be a pair of Dictionary objects, with one for going from Char to Integer and the other for the opposite way. Using a Dictionary there will be no searching. You just pass in one value and get the other back.

I'm not sure whether you have considered this but will your "language" actually work? From your example it would appear that the letter "l" would have a value of 11, but if you want to translate 11 back to letters, will it be "l" or "aa"? Maybe you already have a method for handling that but I would think that all your numbers would have to be the same length, e.g. padded with zeroes if required.
 
Ok, so(based off as if im doing it from the previously stated post) when I add,(charDiction.Add(a, 1)), It says that a is not stated. So I have to include a variable for each letter?

dim a as new char?????
 
Fixed

I discovered a new way to do it, it takes up time, but it works.

I used this:

textbox2.text = textbox1.text.replace("a", "01 ").replace("b", "03 "), etc...
 
It would be much better to use either an array or a dictionary and loop through the characters in the message you want to encode.
By the way, I hadn't come across Dictionaries before. Thank you to jmcilhinney for that extra information.
 
Back
Top