Created
March 19, 2021 19:06
-
-
Save daira/679a16cd048132622cbc019e36a05730 to your computer and use it in GitHub Desktop.
rtl addition chain v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---> up to here is a multiple of 0b110011 = 51 :-) | |
x_p = 0b11001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001101001110100111101110000011001001101000010000101001100000111000101110000011110000111100111111000011001100110011001100110011001101 | |
pchain = Chain() | |
pi = pa = 1 | |
for i in range(1, 128): | |
pi = pchain.sqr(pi) | |
if '01001110100111101110000011001001101000010000101001100000111000101110000011110000111100111111000011001100110011001100110011001101'[127-i] == '1': | |
pa = pchain.mul(pa, pi) | |
#b = '1000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100011010001101' | |
b = '1000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001' | |
assert int(b, 2)*0b110011 == 0b110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011 | |
pj = pchain.sqrmul(pi, 1, pi) | |
pk = pchain.sqrmul(pj, 4, pj) | |
for k in range(1, 122): | |
pk = pchain.sqr(pk) | |
if b[121-k] == '1': | |
pa = pchain.mul(pa, pk) | |
assert pa == x_p, "\n" + format(pa, '0255b') + "\n" + format(x_p, '0255b') | |
print(pchain) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment