32 bit random numbers

Anything QL Software or Programming Related.
stevepoole
Super Gold Card
Posts: 715
Joined: Mon Nov 24, 2014 2:03 pm

Re: 32 bit random numbers

Post by stevepoole »

Hi Bwinkel,

Getting a little off the main subject, you mention that pseudo-random numbers are used in cryptography.

I have written a short routine which encrypts without pseud-orandoms.

Here is the bit-stream, clear message and the encoded one. Is there any accepted QL encryption method?

Steve.
___________________
Capture d’écran (499)BIS.jpg


User avatar
bwinkel67
QL Wafer Drive
Posts: 1196
Joined: Thu Oct 03, 2019 2:09 am

Re: 32 bit random numbers

Post by bwinkel67 »

How did you encrypt? The simplest general encryption method (not tied to any platform) is a stream cipher where you take your random bit-stream and x-or it to your message to get the cipher text.

Btw, if your bit-stream is not pseudo-random, then I'm guessing it is true random? If so, the downside is that your entire bit-stream becomes your key which isn't all that practical, i.e. if you can't re-generate the exact bit-stream then you have to save all of it (imagine trying to encrypt War and Peace). That's why pseudo-random number generators are preferred for stream ciphers.


stevepoole
Super Gold Card
Posts: 715
Joined: Mon Nov 24, 2014 2:03 pm

Re: 32 bit random numbers

Post by stevepoole »

Hi Bwinkel,

The bit stream IS the encrypted message.

Not being a specialist, I do not know how to describe the encryption method. But it is very simple !

Steve.
____________


User avatar
bwinkel67
QL Wafer Drive
Posts: 1196
Joined: Thu Oct 03, 2019 2:09 am

Re: 32 bit random numbers

Post by bwinkel67 »

So the confusing part here is that you listed three things:

1) bit-stream
2) clear message
3) encoded one

Generally the clear message is M, the message text. The encoded message is referred to as C, the ciphertext, the result of the encryption that should be safe. So what is the bit-stream? Is it just a binary representation of the ciphertext then?

With simple encryption, such as a stream cipher, it sort of follows the encoder ring metaphor we might have gotten out of a cereal box back in the 70's. You shift each letter by some amount. If you use a Caesar cipher (extremely simple), you pick a common sift and keep it:
  • Say we have HELLO and we shift everything by 2, then we'd get JGNNQ
Now if you want to create some sort of sequence you can make it a bit more complex. We could use an increment (again, very simple and not very strong):
  • Again, we have HELLO and we shift by 1,2,3,4,5,.., the we get IGOPT
But instead of an increment we can use a random sequence that say an LGR like Park-Miller gives us.
  • So using HELLO again and a sequence like 1339384040, 156903, 12330567, 1010393444, 45660 and if we shift with modulus 26 we'd get BXATS
  • i.e. For the first one, H is 7 and 1339384040 mod 26 is 20, so 20+7 mod 26 is 1 which is B (if A is 0, B is 1, C is 2, etc...)
That's a simple way of looking at it. Stream ciphers use the XOR operation instead of additional/subtraction, but the latter makes it easier to understand and doesn't necessarily change it too much. The "key" in this case is the number in the sequence that precedes 1339384040, i.e. in the x = (x*p1 + p2) % N formula, to get the new x (1339384040) we start with a previous x that gets multiplied by p1, has p2 added to it and the whole thing is modulus the cycle, which for Park-Miller is 2^31-1 (and for a good LGR no value in the sequence can repeat until all 2^31-1 values have been seen).

The problem with stream ciphers is that the bitstream (i.e. random sequence) you are encoding against is independent of the message text so that if you use the same key and encrypt two stings that are mostly the same except say a few characters in the middle, the two ciphertexts will be identical and from that you could glean some information to help you decipher it.

Block ciphers are designed to mitigate that and so the process gets more complicated as you permutate a larger number of bits at a time (64 bits for AES) and then have to string consecutive blocks together with another process when encrypting large amounts of data. In this case the "key" again starts out this process and why I pointed out the issue about repeatability in cryptography. Things have to be deterministic or you can't undo what you are hiding.


stevepoole
Super Gold Card
Posts: 715
Joined: Mon Nov 24, 2014 2:03 pm

Re: 32 bit random numbers

Post by stevepoole »

Hi Bwinkel,

<< So what is the bit-stream? Is it just a binary representation of the ciphertext then? >> YES !

<< Things have to be deterministic or you can't undo what you are hiding. >> The readable text shown IS the decoded encrypted text...

Of course both sender and receiver have to have the same codec routines, but no XORing is used.

The simple bit scrambling is acheived otherwise...

Steve.
__________________


User avatar
bwinkel67
QL Wafer Drive
Posts: 1196
Joined: Thu Oct 03, 2019 2:09 am

Re: 32 bit random numbers

Post by bwinkel67 »

I'd love to know how the encoding is done since that's at the heart of your encryption. As you saw on my example, for a stream cipher, the most critical element is the random sequence (pseudo) since the XOR of it to the message text yields the cipher text and there is absolute no guessing on what goes on there.

So, how are you encrypting, what's the process? What is the general idea of the encryption, i.e. as opposed to the BASIC code, when you encrypt/encode, what were you trying to accomplish. Would be neat to see your idea. What's interesting is that your ciphertext seems bigger than your message, so are you generating some set blocks?


stevepoole
Super Gold Card
Posts: 715
Joined: Mon Nov 24, 2014 2:03 pm

Re: 32 bit random numbers

Post by stevepoole »

Hi Bwinkel,

I PMed the codec so you could see it, but forgot to indicate, to Let Bp=0 when you run it to remove beeping...

Then it should 'scramble' and decrypt at its best speed.

As you can see, the program uses a common coding technique, which I adapted for scrambling...

It could be of marginal interest, but I am not proposing that it be adopted for QLs !

Regards,
Steve.
_______________


Post Reply