summaryrefslogtreecommitdiff
path: root/3544/CH4/EX4.5/Ex4_5.sce
diff options
context:
space:
mode:
Diffstat (limited to '3544/CH4/EX4.5/Ex4_5.sce')
-rw-r--r--3544/CH4/EX4.5/Ex4_5.sce36
1 files changed, 36 insertions, 0 deletions
diff --git a/3544/CH4/EX4.5/Ex4_5.sce b/3544/CH4/EX4.5/Ex4_5.sce
new file mode 100644
index 000000000..c588dc704
--- /dev/null
+++ b/3544/CH4/EX4.5/Ex4_5.sce
@@ -0,0 +1,36 @@
+// RSA Encryption scheme
+
+p = 7 //Large prime numbers
+q = 17 //Small values taken here for convenience of calculation
+ //and explanation
+
+n = p*q
+z = (p-1)*(q-1)
+
+e = 5 // e<n and e & z are coprime
+
+i=1
+d = i
+while(1==1) //Calcualtion of 'd' from e and z
+ if modulo(i*e,z)==1 then // (e*d)mod z = 1
+ d=i
+ break
+ end
+ i=i+1
+end
+
+printf("\nPublic Key: (%d,%d)\nPrivate Key: (%d,%d)\n\n",n,e,n,d)
+
+PT = 10 //Example plaintext
+
+printf("Plaintext: %d\n",PT)
+
+C = modulo(PT^e,n)
+printf("\nEncrypted Text Code: %d\n\n",C)
+
+PT=1
+for i = 1:d
+ PT = modulo(PT*C,n)
+end
+
+printf("Decrypted Text: %d\n",PT) //Conversion to plain text in ASCII