-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniversalCompiler.py
More file actions
60 lines (46 loc) · 1.43 KB
/
UniversalCompiler.py
File metadata and controls
60 lines (46 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import sys
import urllib2
# Class from ANU's website
class ANURandom:
BINARY = "BINARY"
HEX = "HEX"
CHAR = "CHAR"
def getRandom(self,type):
if type == self.BINARY:
url = 'http://150.203.48.55/RawBin.php'
elif type == self.HEX:
url = 'http://150.203.48.55/RawHex.php'
elif type == self.CHAR:
url = 'http://150.203.48.55/RawChar.php'
page = urllib2.urlopen(url, timeout=5)
data = page.read()
num = data.split('"rng"')[1].split('<td>\n')[1].split('</td>')[0]
return num
def getBin(self):
return self.getRandom(self.BINARY)
def getHex(self):
return self.getRandom(self.HEX)
def getChar(self):
return self.getRandom(self.CHAR)
num_bytes = 0
if(sys.argv[1].isdigit()):
num_bytes = int(sys.argv[1])
else:
affirmation_filename = sys.argv[1]
affirmation_text = ''
with open(affirmation_filename, 'r') as affirmation_file:
affirmation_text = affirmation_file.read()
affirmation_len = len(affirmation_text)
print("affirmation len: " + str(affirmation_len))
num_bytes = affirmation_len
data = ''
generator = ANURandom()
while len(data) < num_bytes:
data += generator.getChar()
data.encode()
output_filename = sys.argv[2]
with open(output_filename, 'wb') as output_file:
output_file.write(data)
# Note: not recommended for unlucky people
if "-e" in sys.argv:
eval(data)