1
$\begingroup$

I need an array populated with characters and integer keys for each, and I want to, using this set, encode messages, and then decode them later on . Essentially I am trying to write RSA algorithm for this. However, the maths of it is what I am still kind of lost on. In order to encode, I would have to encode bits of the input string, and this after reading the corresponding key for each character, M.

     Ciphertext=0       for i from 1 to length(message) do          M:= ltable[message[i]] // Read the number that corresponds to the Character         ciphertext:= ciphertext * ((M^encryptionkey) mod modfactor);//encode the returned number and add to ciphertext     Loop next        return ciphertext;  //To Convert all the input message at once, and then encode I have this algorithm  ** for i from 1 to length(message) do          M:= ltable[message[i]]//get the number that corresponds to character         ciphertext:= ciphertext * M;//perform operation to update     Loop next        return ((ciphertext^encryptionkey) mod modfactor);** 

i.e Ciphertext = M^e mod n where C is the resulting ciphertext, e is my encryption key and modfactor is the product of my primes.

The code above spews out my input message in an encrypted form. However, when I am to decode to resulting ciphertext, I run into some problem reversing the operations above to get the exact message that was sent as input to my encryption program. Essentially given a String of length 100, I encrypt each character of the input string with the above, but to reverse/decode, I don't seem to be getting the same message.

cipher = cyphertext; while cipher> 0 do rest = (cipher ^decryptionkey) mod modfactor message = concatenate(ntable[rest],message): wrk = (cipher/rest)/modfactor
End While

Return message

The code/algorithm above does not seem to work. Test primes used are p=263 and q=911, and encryptionkey= 27 How do I accomplish this please?

  • 0
    You have to compute $\text{cipher}^{\,d}$ mod $n$ where $d=e^{-1}$ mod $\varphi(n)$ is the decryption key. Could you point out more specifically what "some problem" is?2012-03-05
  • 0
    I do have my encryption and decryption keys worked out. The problem is the how of encryption and then decryption the message input, I mean the algorithm for encryption 1 character at a time and then decryption to yield each character at a time.2012-03-05
  • 0
    The problem is that your message is *way* bigger than your `modfactor`, so even without encryption if you turned the message into a number and then reduced modulo pq and then turned back into a string of characters, you'd get something different.2012-03-05
  • 0
    That is why I had it encoding my information one character at a time initially. If I have an input that hundreds of lines long, I still would like to be able to handle that without needing to keep looking for bigger and bigger prime numbers each time.2012-03-05
  • 0
    I see. I imagine you're supposed to break the message into pieces, each piece as big as possible without letting the corresponding number go over modfactor - though the primes involved still preferably large. I'm not the go-to guy for details on the protocol though, sorry.2012-03-05
  • 0
    Thanks.I probably will end up breaking it up into bits. I thought it was possible to, looking at the algorithm for encrypting, I have above for encrypting all my string input at once, to come up with a way that will work for decrypting as well.2012-03-05

2 Answers 2