/* This script for GNU bc (binary calculator) illustrates the RSA algorithm Read the comments to understand more of it. I am not a cryptographer, so I cannot make any claims about the strength or correctness of this script. No warranty. (c) Bart Vanhauwaert, 2002 bvh@irule.be This code is distributed under the GNU public license */ define euclid(a,b) { auto mult,rem mult = a/b; rem = a%b; if (rem != 1) { tmp = euclid(b,rem); ll1 = l2; ll2 = l1 - mult*l2; l1 = ll1; l2 = ll2; } else { l1 = 1; l2 = -mult; } } define expmod(a,b,m) { if (b == 1) { return (a%m); } else { if ( (b%2) == 0 ) { return (expmod((a*a)%m,b/2,m)); } else { return ((expmod(a,b-1,m)*a)%m); } } } define isprime(n) { if (expmod(2,n-1,n) != 1) return (0); if (expmod(3,n-1,n) != 1) return (0); if (expmod(5,n-1,n) != 1) return (0); if (expmod(7,n-1,n) != 1) return (0); if (expmod(13,n-1,n) != 1) return (0); return (1) } define firstprime(n) { for (i=n; i