Skip to content

Commit 99f1699

Browse files
committed
Edited encryption2.py to use new encryption key with 3[sqrt(2)] elements
Caused edits in Amber-Spyglass-Encrypted.txt and Amber-Spyglass_Encrypted-Enumerated.json Created TRNG.py and TRNG2.py TRNG.py created randorgTRNG.json, which was used to generate randorgTRNG2.json and randorgTRNG3.json TRNG2.py created TRNG2.json TRNG.py uses diy b26 conversion. TRNG2.py uses Nerdull TRNG converter Also created sysTRNG.json, which uses random.Systemrandom() to generate
1 parent 8db4954 commit 99f1699

13 files changed

+114
-4
lines changed

2022-08-01.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

2022-08-all.bin

30 MB
Binary file not shown.

2022-09-12.bin

1 MB
Binary file not shown.

Amber-Spyglass-Encrypted.txt

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Amber-Spyglass_Encrypted-Enumerated.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

TRNG.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,19 @@ def sysrandom(len=1000000):
1414
sys.append(rng.randint(1,26))
1515
return sys
1616

17+
def randorg():
18+
output = []
19+
with open("2022-08-01.txt","r") as file:
20+
bitsource = file.readline()
21+
decimal = int(bitsource,2)
22+
print("Converting randorgTRNG to base26")
23+
#Convert to base26
24+
while decimal != 0:
25+
output.append(decimal%26)
26+
decimal = decimal//26
27+
output = output[::-1]
28+
return output
29+
1730
if __name__ == "__main__":
1831
writejson(sysrandom(),"sysTRNG.json")
32+
writejson(randorg(),"randorgTRNG.json")

TRNG2.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

TRNG2.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import numpy as np
2+
from bitstring import Bits, ConstBitStream
3+
import json
4+
5+
6+
class Provide(object):
7+
'''
8+
A class interpreting a string of random bits in a sophisticated manner,
9+
so as to provide three major categories of random numbers:
10+
1. uniformly drawn random integers,
11+
2. uniformly drawn random decimals,
12+
3. normally distributed complex random numbers.
13+
'''
14+
15+
def __init__(self, source):
16+
'''
17+
Parameters:
18+
source: str
19+
Random-bit source file generated by RANDOM.ORG.
20+
'''
21+
self.source = source
22+
23+
def integer(self, N, M, offset=0):
24+
'''
25+
Provide an array of random integers following uniform distribution.
26+
Parameters:
27+
N: int
28+
Amount of provided integers.
29+
M: int
30+
Upper range (exclusive) of the integers,
31+
Which can only take a value among 0, 1, ..., M-1.
32+
offset: int
33+
Amount of bits at the beginning of the file to be skipped over.
34+
Returns:
35+
result: 1d numpy array
36+
'''
37+
width = int(np.ceil(np.log2(M)))
38+
blob = ConstBitStream(filename=self.source)
39+
result = np.empty(N, dtype="u4") # 32-bit unsigned integer in native endian
40+
blob.pos = offset
41+
for i in range(N):
42+
while True:
43+
number = blob.read(width).uint
44+
if number < M:
45+
result[i] = number
46+
break
47+
return result
48+
49+
def uniform(self, N, offset=0):
50+
'''
51+
Provide an array of random decimals following uniform distribution
52+
in the half-open range [0, 1).
53+
Parameters:
54+
N: int
55+
Amount of provided decimals.
56+
offset: int
57+
Amount of bits at the beginning of the file to be skipped over.
58+
Returns:
59+
result: 1d numpy array
60+
'''
61+
sign = '0' # sign bit denoting positive
62+
exponent = '0' + '1' * 10 # exponent bits denoting 0
63+
prefix = "0b" + sign + exponent # the bit order entails big endian
64+
blob = Bits(filename=self.source, length=52*N, offset=offset)
65+
buf = Bits().join([prefix+mantissa for mantissa in blob.cut(52)])
66+
result = np.frombuffer(buf.bytes, dtype=">f8") - 1 # 64-bit double precision in big endian
67+
return result
68+
69+
def gaussian(self, N, offset=0):
70+
'''
71+
Provide an array of complex random numbers following the
72+
standard complex Gaussian distribution (zero mean, unit variance).
73+
Parameters:
74+
N: int
75+
Amount of provided complex numbers.
76+
offset: int
77+
Amount of bits at the beginning of the file to be skipped over.
78+
Returns:
79+
result: 1d numpy array
80+
'''
81+
decimals = self.uniform(2*N, offset)
82+
result = np.sqrt(-np.log(decimals[::2])) * np.exp(2j*np.pi*decimals[1::2])
83+
return result
84+
85+
86+
if __name__ == "__main__":
87+
provide = Provide("Projects\\EE\\2022-08-all.bin")
88+
integers = provide.integer(1000000, 26)
89+
integers = integers + 1
90+
with open("Projects\\EE\\TRNG2.json","w") as f:
91+
json.dump(integers.tolist(),f)

encryption2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def decrypt(ciphertext,keyfile):
101101
y = decrypt(x,"pi-with-coprime2023-b26.json")
102102
print(y)
103103

104-
writetxt(encrypt(loadtxt("Amber-Spyglass-Clean.txt"),"pi-with-coprime2023-b26.json"),"Amber-Spyglass-Encrypted.txt")
104+
writetxt(encrypt(loadtxt("Amber-Spyglass-Clean.txt"),"testkeygen3.json"),"Amber-Spyglass-Encrypted.txt")
105105
writejson(FormatTextToNum(loadtxt("Amber-Spyglass-Encrypted.txt")),"Amber-Spyglass_Encrypted-Enumerated.json")
106106
#b26 = convertbase26(loadkeysbase10("coprime-digits-mod10-2023-1000k.json","pi-digits.json",length=1000000))
107107
#b26 = convertbase26(loadkeysbase10("pi-digits.json",length=1000000))

randorgTRNG.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)