Reputation: 13
I have a program that uses encryption text strings, I basically just want to write a simple program that will print out all of the decrypted text for me.
For example: Say that the letter "A" = the byte "2C"; I would want to type the letter A in to the program and have it print out "2C" for me.
Does anybody know an easy way to do this?
Many thanks!
Upvotes: 0
Views: 114
Reputation: 2421
By 2C
I think you mean the hex representation of the letter A
?
That would be something like String.Format("{0:X}", Convert.ToInt32('A'));
Update after clarification from OP
You either need to predefine your entire supported character set like this.
static Dictionary<char, int> cyper = new Dictionary<char, int>
{
{'A', 44},
{'B', 45},
{'C', 46},
{'D', 47},
{'E', 48},
{'F', 49},
// .. etc
};
// ...
Console.WriteLine(string.Format("{0:X}", cyper['A'])); // will print 2C
But that doesn't seem like a very good encryption if everything is just off by a few values.
Another approach would be to apply an encoding scheme. A runtime mathematical evaluation on the input that will evaluate to 2C (encrypt) and be able to take 2C and evaluate to A (decrypt).
Upvotes: 1
Reputation: 172578
I would suggest you to try like this:
byte[] b = System.Text.Encoding.UTF8.GetBytes (yourString);
Upvotes: 0