Skip to content

Instantly share code, notes, and snippets.

@reardencode
Created May 9, 2024 19:13
Show Gist options
  • Save reardencode/07276966987a23055b694619222c43bf to your computer and use it in GitHub Desktop.
Save reardencode/07276966987a23055b694619222c43bf to your computer and use it in GitHub Desktop.
restored script RSA
<n> <c> <e> // n, c = RSA key len, e = 3 bytes
| n e c |
TUCK | n e c e | 512 | 1024
1 | n e c e 1 |
AND | n e c 0/1 | 257 | 513
IF | n e c |
DUP | n e c c | 512 | 1024
ELSE | n e c |
1 | n e c 1 |
ENDIF | n e c c/1 |
TOALT | n e c |
23x {
DUP | n e c c | 512 | 1024
MUL | n e cx | 16898 | 66562
2 | n e cx 2 |
PICK | n e cx n | 512 | 1024
MOD | n e cx | 85248 | 334336
SWAP | n cx e |
1 | n cx e 1 |
DOWNSHIFT | n cx ex | 7 | 7
TUCK | n ex cx ex | 512 | 1024
1 | n ex cx ex 1 |
AND | n ex cx 0/1 | 7 | 7
IF | n ex cx |
DUP | n ex cx cx | 512 | 1024
FROMALT | n ex cx cx a |
MUL | n ex cx a | 16898 | 66562
3 | n ex cx a 3 |
PICK | n ex cx a n | 512 | 1024
MOD | n ex cx a | 85248 | 334336
TOALT | n ex cx |
ENDIF | n ex cx |
}
2DROP | n |
DROP | |
FROMALT | a |
total script size: 9+23*20+3=472B
2048b total witness size: 4+256+256+3+472=991B
2048b total varops:
512+257+512+23*(512+16898+512+85248+7+512+7+512+16898+512+85248)=4759199
2048b varops per byte: 4759199/991~=4802.5
4096b total witness size: 4+512+512+3+472=1503B
4096b total varops:
1024+513+1024+23*(1024+66562+1024+334336+7+1024+7+1024+66562+1024+334336)=18561951
4096b varops per byte: 18561951/1503~=12350
A*B: len(A)+len(B)+(len(A)/8*len(B)+1)*2
A%B: 5*len(A)+3*len(B)+(len(A)-len(B))/8*(4*len(B)+3*len(A))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment