I am learning about cryptographic algorithms and in the process am attempting to implement some well known schemes. I understand the mathematical explanations behind RSA and El Gamal, but am currently unable to test my implementations of either. The underlying problem is that I cannot see the way to convert plain text into a manipulatable number.
For Example:
Message = "This is a message I want to encrypt";
int x = (int)Message;
Encrypt(x,key);
In my mind, it should be possible to cast a string to an integer, but doing so in a method similar to the above example doesn’t work. How can I turn a plain-text message into a numerical value (and later back into a plain-text value) for the purposes of encryption?
There are usually two steps to converting a string to an integer. The first is to convert each character into a small integer and then convert the resulting sequence of small integers into a large integer. For example, in Java or C# you can easily convert the string into a byte array representing its UTF-8 encoding. Then, by treating the byte array as a base-256 integer, you can convert it to a large integer. Every BigInteger package that I am aware of has a constructor that will accept an array of bytes, as well as a method that will go the other way and take the BigInteger and return an array of bytes.