Skip to content

Instantly share code, notes, and snippets.

@notcod
Created August 1, 2021 00:22
Show Gist options
  • Select an option

  • Save notcod/0f7ef646c800938edd7012953233098d to your computer and use it in GitHub Desktop.

Select an option

Save notcod/0f7ef646c800938edd7012953233098d to your computer and use it in GitHub Desktop.
Simple ETH gen Python
from operator import xor
from functools import reduce
from random import randrange
Rc = [
0x0000000000000001, 0x0000000000008082, 0x800000000000808A, 0x8000000080008000,
0x000000000000808B, 0x0000000080000001, 0x8000000080008081, 0x8000000000008009,
0x000000000000008A, 0x0000000000000088, 0x0000000080008009, 0x000000008000000A,
0x000000008000808B, 0x800000000000008B, 0x8000000000008089, 0x8000000000008003,
0x8000000000008002, 0x8000000000000080, 0x000000000000800A, 0x800000008000000A,
0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008
]
Rt = [[0,1,62,28,27,],[36,44,6,55,20,],[3,10,43,25,39,],[41,45,15,21,8,],[18,2,61,56,14,]]
Ms = [0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295, 8589934591, 17179869183, 34359738367, 68719476735, 137438953471, 274877906943, 549755813887, 1099511627775, 2199023255551, 4398046511103, 8796093022207,17592186044415, 35184372088831, 70368744177663, 140737488355327, 281474976710655, 562949953421311, 1125899906842623, 2251799813685247, 4503599627370495, 9007199254740991, 18014398509481983, 36028797018963967, 72057594037927935, 144115188075855871, 288230376151711743, 576460752303423487, 1152921504606846975, 2305843009213693951, 4611686018427387903, 9223372036854775807, 18446744073709551615]
def K(s):
b = []
b += s
bb = b + [1] + [0] * (134 - len(b)) + [128]
m = [[0] * 5 for x in range(5)]
bb += [0] * 64
i = 0
for y in range(5):
for x in range(5):
r = 0
for b in reversed(bb[i:i + 8]):
r = r << 8 | b
m[x][y] ^= r
i += 8
for ir in range(24):
C = [reduce(xor, m[x]) for x in range(5)]
D = [0] * 5
for x in range(5):
D[x] = C[(x - 1) % 5] ^ ((C[(x + 1) % 5] & Ms[63]) << 1 | C[(x + 1) % 5] >> 63)
for y in range(5):
m[x][y] ^= D[x]
B = [[0] * 5 for x in range(5)]
for x in range(5):
for y in range(5):
B[y % 5][(2 * x + 3 * y) % 5] = (m[x][y] & Ms[64 - Rt[y][x]]) << Rt[y][x] | m[x][y] >> (64 - Rt[y][x])
for x in range(5):
for y in range(5):
m[x][y] = B[x][y] ^ ((~ B[(x + 1) % 5][y]) & B[(x + 2) % 5][y])
m[0][0] ^= Rc[ir]
out = [0] * 200
i = 0
for y in range(5):
for x in range(5):
v = []
for b in range(0, 64, 8):
v.append((m[x][y] >> b) & 0xff)
out[i:i+8] = v
i += 8
for ir in range(24):
C = [reduce(xor, m[x]) for x in range(5)]
D = [0] * 5
for x in range(5):
D[x] = C[(x - 1) % 5] ^ ((C[(x + 1) % 5] & Ms[63]) << 1 | C[(x + 1) % 5] >> 63)
for y in range(5):
m[x][y] ^= D[x]
B = [[0] * 5 for x in range(5)]
for x in range(5):
for y in range(5):
B[y % 5][(2 * x + 3 * y) % 5] = (m[x][y] & Ms[64 - Rt[y][x]]) << Rt[y][x] | m[x][y] >> (64 - Rt[y][x])
for x in range(5):
for y in range(5):
m[x][y] = B[x][y] ^ ((~ B[(x + 1) % 5][y]) & B[(x + 2) % 5][y])
m[0][0] ^= Rc[ir]
return ''.join(format(x, '02x') for x in out[:136][:32])
def G(s):
a = '0x'
z = str(bin(s))[2:]
l = len(z)
p = 115792089237316195423570985008687907853269984665640564039457584007908834671663
x = Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240
y = Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424
for i in range(1, l):
lm, hm = 1, 0
lw, hg = 2*y % p, p
while lw > 1:
ro = hg//lw
nm, nw = hm-lm*ro, hg-lw*ro
lm, lw, hm, hg = nm, nw, lm, lw
R = lm % p
o = 3*x*x*R % p
u = o*o-2*x
y = (o*(x-u % p)-y) % p
x = u % p
if z[i] == "1":
lm, hm = 1, 0
lw, hg = (Gx - x) % p, p
while lw > 1:
ro = hg//lw
nm, nw = hm-lm*ro, hg-lw*ro
lm, lw, hm, hg = nm, nw, lm, lw
R = lm % p
o = (Gy-y)*R % p
u = o*o-x-Gx
y = (o*(x-u % p)-y) % p
x = u % p
Px = hex(x)[2:]
Py = hex(y)[2:]
Px = '0' * (64-len(Px)) + Px
Py = '0' * (64-len(Py)) + Py
se = bytes.fromhex(Px + Py)
b = K(se)[24:]
k = K(b.encode('utf-8'))
for i in range(40):
ac = b[i]
kc = k[i]
if int(kc, 16) >= 8:
ac = ac.upper()
a += str(ac)
k = hex(s)[2:]
k = '0'*(64-len(k)) + k
b = 0
if b != 0:
f = open("keys.txt", "a")
f.write("\n|" + k + "_" + a)
f.close()
print("Found!")
return (b, a, k)
while True:
data = G(randrange(115792089237316195423570985008687907853269984665640564039457584007913129639935))
print(str(data[0]) + " " + data[1] + " " + data[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment