Skip to content

Instantly share code, notes, and snippets.

@Vinc0682
Created March 31, 2017 20:19
Show Gist options
  • Save Vinc0682/d55c7fcde434b2965fd7f781f516f4e0 to your computer and use it in GitHub Desktop.
Save Vinc0682/d55c7fcde434b2965fd7f781f516f4e0 to your computer and use it in GitHub Desktop.
0 JMP 4 # Uses the Blum-Macali-Algorithm https://en.wikipedia.org/wiki/Blum%E2%80%93Micali_algorithm
1 DEF 2 # g, a primitive root of "p"
2 DEF 37 # p, a prime number :)
3 DEF 2 # x, The last random number
4 JSR 20 # x = g^x
5 JSR 50 # x = x mod p
6 OUT 3 # print result
7 INM 127 # Wait for the user to accept it
8 LDA 127
9 JNZ 4 # Next number :)
10 END
120 NOP 0 # Pow-Function
20 DEF 0 # i, our iterator
21 DEF 0 # t, temporary result
24 LDA 3
25 SUB 20
26 JNP 34 # i >= x
27 LDA 21
28 ADD 1
29 STA 21 # t += g
30 LDA 20
31 INC
32 STA 20 # i += 1
33 JMP 24
34 LDA 21
35 STA 3
36 LDA 126
37 STA 20
38 LDA 126 # i = 0
39 STA 21 # t = 0
40 RTN
120 NOP 0 # mod-Function
50 DEF 0 # k, second temporary result
51 LDA 3
52 STA 50 # k = x
53 LDA 50
54 SUB 2
55 JNP 60 # while ((t - p) > 0)
56 LDA 50
57 SUB 2
58 STA 50 # t = t - p
59 JMP 53
60 LDA 50
61 STA 3
63 LDA 126
64 STA 50 # k = 0
65 RTN
126 DEF 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment