summaryrefslogtreecommitdiff
path: root/3544/CH4/EX4.5
diff options
context:
space:
mode:
authorprashantsinalkar2017-10-10 12:27:19 +0530
committerprashantsinalkar2017-10-10 12:27:19 +0530
commit7f60ea012dd2524dae921a2a35adbf7ef21f2bb6 (patch)
treedbb9e3ddb5fc829e7c5c7e6be99b2c4ba356132c /3544/CH4/EX4.5
parentb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (diff)
downloadScilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.gz
Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.bz2
Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.zip
initial commit / add all books
Diffstat (limited to '3544/CH4/EX4.5')
-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