Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

I hope my question isn't as lazy as the title indicates. What I want to ask is how people literally integrate a PRNG with encrypting material.

I wrote a silly little script in Python a while back that took a 9 digit seed, then produced a list of 'random' numbers using a linear congruential generator. That was cool and all, but when I tried to use that with my silly internet chat program (Also in python) I failed to see what use it had. Hey, I could match letters, symbols, and numbers to the various digits as a sort of substitution cipher, but that didn't seem really secure at all. If substitution was used every-time, then no generator would be better than the other

I googled for a bit about my question, but all the results didn't seem to go into any specifics about how one would use these randomly generated numbers to encrypt anything. Anyhow, I chose to give it a shot on Cypto, and am hoping someone can either point me to an answer so this can be closed, or equally, provide an explanation.

share|improve this question
    
Ignoring the fact that there are much better algorithms available, I guess it can’t hurt to mention the existence of Alternating Step Generators… which may (or may not) be interesting for you to learn about. –  e-sushi May 19 at 15:01
add comment

1 Answer 1

up vote 2 down vote accepted

Well, first of, a linear congruential generator is not a secure pseudo random number generator at all, but if it's just about the basic understanding, we can ignore how you get that stream of random numbers for now.

So, but can you actually use this? The easiest approach is using the stream of random numbers in a stream cipher and just XOR each bit of the message with the according bit in the stream. For the actual implementation your RNG will provide a fixed number of bits and you need to keep track of how many bits you actually used. And then you transmit the result instead of the message itself.

On the other side you do the same.

An alternative would be to work on 8-bit symbols, and you just add the values together (modulo 256). Pseudo code:

Input: message as char array m[]
rng(): call to the RNG, returns an 8-bit integer array of length r.

j = 0
temp = rng()

for i from 0 to m.length:
  m[i] = (int(m[]) + temp[j]) % 256
  i++
  j++
  if (j > 255)
    j=0
    temp = rng()

Maybe this can be made more compact, but it should work for a toy project.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.