Skip to content

Instantly share code, notes, and snippets.

@vinloo
Last active June 11, 2019 13:43
Show Gist options
  • Select an option

  • Save vinloo/8da9fa31d880a452f4723748b49c15ce to your computer and use it in GitHub Desktop.

Select an option

Save vinloo/8da9fa31d880a452f4723748b49c15ce to your computer and use it in GitHub Desktop.
Find decryption function of lineair encryption function
ClrHome
Disp "E(x) = ax + b in Z(m)"
Input "m = ",M
Input "a = ",A
Input "b = ",B
ClrHome
Output(1,1,"E(x) = "+toString(A)+"x + "+toString(B)+" in Z("+toString(M)+")")
Output(4,1,"Calculating...")
remainder(A,M)→H
For(I,1,M)
If remainder((H*I),M)=1
Then
I→P
Goto 1
End
End
Lbl 1
ClrHome
M-P*B→Q
Output(1,1,"E(x) = "+toString(A)+"x + "+toString(B)+" in Z("+toString(M)+")")
If B=0
Then
Output(4,1,"D(y) = "+toString(P)+"y MOD "+toString(Q))
Else
Output(4,1,"D(y) = "+toString(P)+"y + "+toString(Q)+" MOD "+toString(M))
End
For(I,1,6)
Disp ""
End
Pause "Press enter to exit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment