Topic: A Simple Prime Number Trick (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=33321" title="Pages that link to Topic: A Simple Prime Number Trick (Page 1 of 1)" rel="nofollow" >Topic: A Simple Prime Number Trick <span class="small">(Page 1 of 1)</span>\

 
warjournal
Maniac (V) Mad Scientist

From:
Insane since: Aug 2000

posted posted 11-24-2018 20:30

Okay, I lied a little bit. Before I go back under my rock, a few more little things.

One day I was reading about crytography and prime numbers and I came across a neat
trick involving periods. If you take two prime numbers, you can create a period that
is p0xp1x2 long.

An easy example is 3x5x2=30:

code:
123
abcde

123123123123123
abcdeabcdeabcde

1a2b3c1d2e3a1b2c3d1e2a3b1c2d3e



Shouldn't be too hard to see that.

And then, some time later, I was reading a book about Fibonocci. It was the usual stuff.
But the section about prime numbers that caught my eye because there was a big list of them.
Being the curious fellow that I am, I started adding them up in pairs. Sure enough,
I found 107+149=256. Yeah!

Why the excitement over that? Because 107 and 149 are primes that add up to 256. This means
that I could very easily create a period of 107x149x2=31886. Very not bad for a series of
(0-255) numbers. Cryptography, anyone?

So, those two prime numbers and (0-255) can create a rather large period. Are there more?
Yes. Check this one out:

code:
53+59+71+73=256
53*59*71*72*4= 64,828,964


Four prime numbers that add up to 256 give a period of 65M. That is one impressive period.

One more:

code:
41+43+47+53+71=255
41*43+47*53*71*5= 1,559,029,715


Yeah... give me (0-254) and I can turn it into a period of 1.6G.
Even though adds up to 255, big deal. Let the last one drop off. Whatever.
I'm not gonna worry about dropping one byte when I'm getting a period that big.

Like a byte stream from a pseudo-random number generator. It has it's purposes in
cryptography.

But there is something else that I can do that can be tossed in. So far just a single series
of (0-255). Oh, dear sweet thing, I can create so much more. How about a sudoku grid
that is 256x256? That's 256 rows, 256 columns, and 256 blocks. Take your bitch-ass
period and multiply it by 768.

code:
1,559,029,715 x 768 = 1,197,334,821,120



Yeah, that's right. Using a 65k file, I can create a period that is 1.2T big.

But I'm probably not going to do all of that. I do enjoy the idea of creating my own space
and making it massive. And I *love* manipulating data. But I am going to keep
this project a little bit smaller. The furthest that I will take this in code
is [53,59,71,73] and a single (0-255). If I ever feel the need to make it bigger,
I know that I can.

I have a very simple way of scrambling data using a password. And I also have a very funny
way of obfuscating filenames (this makes me giggle, kekeke).

Well, here is a quick little code thing that demonstrates:

code:
#!/usr/bin/env python
import random

# random list of (0-255)
c=list(range(256))
random.shuffle(c)

# various variables needed
# feel free to play with the
# prime numbers in pm[]
pm=[53, 59, 71, 73]
pa=[0]
pmd=len(pm)
pn=[]

# generate a list for the slices
for i in range(len(pm)):
    pa.append(pm[i]+pa[i])

# slice the sequence
for i in range(1,len(pa)):
    pn.append(c[pa[i-1]:pa[i]])

# a simple example that will
# print the first 30 to screen
for i in range(30):
    row=i%pmd
    col=int(i/pmd)
    x=pn[row][col%pm[row]]
    print(x)



Works fine in Python 2.7.12 and Python 3.5.2.
You should be good to play with the prime numbers in pm[] (parametric rocks). Change
the numbers and even their order. If you use 4 prime numbers, that's 4! starting points
that you can choose from.

Okay, back under my rock.
I promise this time.
Unless I get some of my roto-scoping done soon.
Heh.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu