Birol ÇAPA Doç. Dr. Sıddıka Berna Örs Yalçın Following code can coompute montgomery multiplication of 128 bit numbers:

Similar documents
Assignment 9 / Cryptography

Blum-Blum-Shub cryptosystem and generator. Blum-Blum-Shub cryptosystem and generator

Encrypted Data Deduplication in Cloud Storage

Other Topics in Cryptography. Truong Tuan Anh

INTERNATIONAL JOURNAL OF ELECTRONICS AND COMMUNICATION ENGINEERING & TECHNOLOGY (IJECET)

TECHNISCHE UNIVERSITEIT EINDHOVEN Faculty of Mathematics and Computer Science Exam Cryptology, Tuesday 31 October 2017

ASYMMETRIC (PUBLIC-KEY) ENCRYPTION. Mihir Bellare UCSD 1

Chapter 9. Public Key Cryptography, RSA And Key Management

Spring 2008, CSC395 Special Topics: Information Security Project 3

CS Network Security. Nasir Memon Polytechnic University Module 7 Public Key Cryptography. RSA.

Number Theory and RSA Public-Key Encryption

Introduction to Cryptography and Security Mechanisms: Unit 5. Public-Key Encryption

Key Exchange. Secure Software Systems

A nice outline of the RSA algorithm and implementation can be found at:

ASYMMETRIC (PUBLIC-KEY) ENCRYPTION. Mihir Bellare UCSD 1

Introduction to Cryptography and Security Mechanisms. Abdul Hameed

Dr. Jinyuan (Stella) Sun Dept. of Electrical Engineering and Computer Science University of Tennessee Fall 2010

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

Public-key encipherment concept

Math236 Discrete Maths with Applications

Public Key Cryptography and the RSA Cryptosystem

0x1A Great Papers in Computer Security

Channel Coding and Cryptography Part II: Introduction to Cryptography

JAVA OPERATORS GENERAL

Lecture 2 Algorithms with numbers

LECTURE NOTES ON PUBLIC- KEY CRYPTOGRAPHY. (One-Way Functions and ElGamal System)

Cryptography Worksheet

Introduction to Cryptography Lecture 7

Activity Guide - Public Key Cryptography

Public Key Algorithms

CS 161 Computer Security

CS61A Lecture #39: Cryptography

Lecture 07: Private-key Encryption. Private-key Encryption

Introduction to Cryptography Lecture 7

CS 161 Computer Security

Encryption Key Search

*E. Madhusudhana Reddy & M.Padmavathamma Department of Computer Science, S.V.University, Tirupati

I.J.E.M.S., VOL. 1(1): 1-6 ISSN X THRESHOLD GENETIC SENSOR SYSTEM TO E-MANUFACTURING SYSTEM

Chapter 9 Public Key Cryptography. WANG YANG

CSCI 454/554 Computer and Network Security. Topic 5.2 Public Key Cryptography

RSA (material drawn from Avi Kak Lecture 12, Lecture Notes on "Computer and Network Security" Used in asymmetric crypto.

Oblivious Transfer(OT)

Outline. CSCI 454/554 Computer and Network Security. Introduction. Topic 5.2 Public Key Cryptography. 1. Introduction 2. RSA

ASYMMETRIC CRYPTOGRAPHY

Information Security. message M. fingerprint f = H(M) one-way hash. 4/19/2006 Information Security 1

Public-Key Cryptography. Professor Yanmin Gong Week 3: Sep. 7

Overview. Public Key Algorithms I

CS 161 Computer Security

What did we talk about last time? Public key cryptography A little number theory

Outline. Public Key Cryptography. Applications of Public Key Crypto. Applications (Cont d)

1 Identification protocols

Cryptography (DES+RSA) by Amit Konar Dept. of Math and CS, UMSL

L13. Reviews. Rocky K. C. Chang, April 10, 2015

Lecture 2 Applied Cryptography (Part 2)

ח'/סיון/תשע "א. RSA: getting ready. Public Key Cryptography. Public key cryptography. Public key encryption algorithms

Digital Signatures. Luke Anderson. 7 th April University Of Sydney.

2 Handout 20: Midterm Quiz Solutions Problem Q-1. On-Line Gambling In class, we discussed a fair coin ipping protocol (see lecture 11). In it, Alice a

1. Diffie-Hellman Key Exchange

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Introduction to Cryptography ECE 597XX/697XX

Encryption. INST 346, Section 0201 April 3, 2018

Encryption Algorithms Authentication Protocols Message Integrity Protocols Key Distribution Firewalls

Algorithms (III) Yu Yu. Shanghai Jiaotong University

Key Exchange. References: Applied Cryptography, Bruce Schneier Cryptography and Network Securiy, Willian Stallings

CS 161 Computer Security

Algorithms (III) Yijia Chen Shanghai Jiaotong University

Digital Signatures. KG November 3, Introduction 1. 2 Digital Signatures 2

CPSC 467b: Cryptography and Computer Security

Algorithms (III) Yijia Chen Shanghai Jiaotong University

Diffie-Hellman. Part 1 Cryptography 136

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Understanding Cryptography A Textbook for Students and Practitioners by Christof Paar and Jan Pelzl. Chapter 6 Introduction to Public-Key Cryptography

Fall 2017 CIS 3362 Final Exam. Last Name: First Name: 1) (10 pts) Decrypt the following ciphertext that was encrypted using the shift cipher:

Distributed Systems. 26. Cryptographic Systems: An Introduction. Paul Krzyzanowski. Rutgers University. Fall 2015

CS 161 Computer Security

Cryptography and Network Security. Sixth Edition by William Stallings

Advanced Crypto. 2. Public key, private key and key exchange. Author: Prof Bill Buchanan

1 Extended Euclidean Algorithm

Kurose & Ross, Chapters (5 th ed.)

Applications of The Montgomery Exponent

AES Code Example

Authentication and Key Distribution

4:40pm - 6:10pm (90 min)

Cryptography Lecture 4. Attacks against Block Ciphers Introduction to Public Key Cryptography. November 14, / 39

Relaxing IND-CCA: Indistinguishability Against Chosen. Chosen Ciphertext Verification Attack

L2. An Introduction to Classical Cryptosystems. Rocky K. C. Chang, 23 January 2015

Cryptography and Network Security

Lecture 30. Cryptography. Symmetric Key Cryptography. Key Exchange. Advanced Encryption Standard (AES) DES. Security April 11, 2005

Cryptography Symmetric Cryptography Asymmetric Cryptography Internet Communication. Telling Secrets. Secret Writing Through the Ages.

Cryptography Functions

Quantum Encryption Keys

RSA. Public Key CryptoSystem

1 Extended Euclidean Algorithm

Solution to Problem Set 8

AP COMPUTER SCIENCE A

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

Homomorphic Encryption

RSA Public Key Encryption 1. Ivor Page 2

Digital Signatures 1

EE 595 (PMP) Introduction to Security and Privacy Homework 1 Solutions

A Tour of Classical and Modern Cryptography

Transcription:

Homework 3 Implementation of Montgomery Multiplication Montgomery multiplier calculates C = A. B mod N as follows: 1. Given integers x, y and 0 x,y m 2. Montgomery Domain: a. x x m d m, = yr mod m 3. Montgomery Multiplication: a. x -1 mod m = xr(yr)r -1 mod m = xyr mod m i. ntg mery ed n r d t x ii. e ned as x, ) 4. es t -1 mod m = (zr)r -1 mod m 5. Compute Montgomery Domain of x using MP(x, R 2 mod m) 6. Compute Result z using MP(z, 1) For example: 1. m = 119 (odd value), x = 63, y = 57 a. 63(57) mod 119 = 21 2. Montgomery Multiplication: a. R > m, choose 2 7 = 128 b. R 2 mod m = 81, R -1 mod m = 53 c. Montgomery Domain: x = xr mod m = MP(x, R 2 mod m) = 63(81) (53) mod 119 = 91 = yr mod m = MP(y, R 2 mod m) = 57(81) (53) mod 119 = 37 d. Montgomery Multiplication: = MP(91, 37) = 91(37) (53) mod 119 = 70 e. es t, 1) = 70(1) (53) mod 119 = 21 Following code can coompute montgomery multiplication of 128 bit numbers: Results are: A: 270902565107982796159539501779943026603 -> 128 Bit Number B: 251052638676463176992136739297869888188 -> 128 Bit Number N: 272320286609021830958597652262355401393 -> Modulus R: 179795676119011098898159522850739282410 -> Result of A x B mod N 1

import java.math.biginteger; public class Program private static final BigInteger ONE = new BigInteger("1"); bits bits bits public static void main(string[] args) String hexstra = "CBCDEFABCDEFABCDEFABCDEFABCDEFAB";//32 x 4 bits = 128 BigInteger A = new BigInteger(hexStrA, 16); System.out.println("A: " + A); String hexstrb = "BCDEFABCDEFABCDEFABCDEFABCDEFABC";//32 x 4 bits = 128 BigInteger B = new BigInteger(hexStrB, 16); System.out.println("B: " + B); String hexstrn = "CCDEFABCDEFABCDEFABCDEFABCDEFAB1";//32 x 4 bits = 128 BigInteger N = new BigInteger(hexStrN, 16); System.out.println("N: " + N); BigInteger Result = montgomerymult(a, B, N); System.out.println("R: " + Result); private static BigInteger montgomerymult(biginteger A, BigInteger B, BigInteger N) BigInteger RSquareModM = ChooseR(N); BigInteger R_I = (RSquareModM.multiply(RSquareModM)).modInverse(N); BigInteger montx = MontgomeryMultiplier(A,RSquareModM,R_I,N); BigInteger monty = MontgomeryMultiplier(B,RSquareModM,R_I,N); BigInteger montz = MontgomeryMultiplier(montX,montY,R_I,N); BigInteger Z = MontgomeryMultiplier(montZ,ONE,R_I,N); return Z; private static BigInteger MontgomeryMultiplier(BigInteger a, BigInteger rsquaremodm, BigInteger r_i,biginteger m) return ((a.multiply(rsquaremodm)).multiply(r_i)).mod(m); private static BigInteger ChooseR(BigInteger m) BigInteger R = ONE; BigInteger Result = ONE; for(int i=0;i<m.bitlength();i++) R = R.shiftLeft(1); R = (R.multiply(R)).mod(m); return Result; 2

Implementation of RSA for 128 Bit Modulus, N and Choosing Two 64- Bit Prime Number p and q and a Public Key, e and Computing the Corresponding Private Key, d First y, and q rime n mbers are h sen and a ated m d s n by sing them and An e rime n mber is h sen by sing. e is the b i key. d which is the private key is calculated by using formula: Messages are encrypted by using: Ciphered messages are decrypted by using: Following code is the implementation of the RSA: Results are: p: 14545081761063098339 q: 12070297673976155981 modulus: 175563466548352926442597621509006015559 publickey: 65537 privatekey: 144904085211918557390379654824984513313 message: sended by RSA message: 9142630131079496597692581303105 encryptbirol: 73189272229893260895603348125714799305 encryptedmessage: 7_½ ³)gÁ_C«4ë<ÚÉ decryptbirol: 9142630131079496597692581303105 decryptedmessage: sended by RSA package RSA; import java.math.biginteger; import java.security.securerandom; public class Main private final static BigInteger ONE = new BigInteger("1"); static SecureRandom random = new SecureRandom(); static BigInteger privatekey; static BigInteger publickey; 3

static BigInteger modulus; public static void main(string[] args) BigInteger message, encryptedmessage,decryptedmessage; String testmessage = "sended by RSA"; byte[] testmessagebytes = testmessage.getbytes(); BigInteger testmessageinteger = new BigInteger(testMessageBytes); GenerateKeys(128); System.out.println("message: " + testmessage); System.out.println("message: " + testmessageinteger); encryptedmessage = encryptbirol(testmessageinteger); System.out.println("encryptedMessage: " +new String(encryptedMessage.toByteArray())); decryptedmessage = decryptbirol(encryptedmessage); System.out.println("decryptedMessage: " + new String(decryptedMessage.toByteArray())); * @param message * @param exponent. * @param n modulo. * @return message^exponent mod modulus. public static BigInteger modulopower(biginteger message, BigInteger exponent, BigInteger modulus) BigInteger r = ONE; for(int i=exponent.bitlength()-1; i>=0; i--) r = montgomerymult(r,r,modulus); if (exponent.testbit(i)) r = montgomerymult(r, message, modulus); return r; * @param N integer * @creates key public static void GenerateKeys(int N) // choose two primes - p and q BigInteger p = new BigInteger("14545081761063098339"); BigInteger q = new BigInteger("12070297673976155981"); // calculate phi BigInteger phi = (p.subtract(one)).multiply(q.subtract(one)); //calculate modulus modulus = p.multiply(q); //choose a public key e w.r.t phi publickey = new BigInteger("65537"); // 2^16 +1; privatekey = publickey.modinverse(phi); 4

System.out.println( "p: " + p ); System.out.println( "q: " + q ); System.out.println( "modulus: " + modulus ); System.out.println( "publickey: " + publickey ); System.out.println( "privatekey: "+ privatekey ); * @param message * @return encrypted message public static BigInteger encryptbirol(biginteger message) BigInteger result = modulopower(message,publickey,modulus); System.out.println("encryptBirol: " + result); return result; * @param encrypted message * @return decrypted message public static BigInteger decryptbirol(biginteger encryptedmessage) BigInteger result = modulopower(encryptedmessage, privatekey, modulus); System.out.println("decryptBirol: " + result); return result; * @param A * @param B. * @param N. * @return C = A x B mod N private static BigInteger montgomerymult(biginteger A, BigInteger B, BigInteger N) BigInteger RSquareModM = ChooseR(N); BigInteger R_I = (RSquareModM.multiply(RSquareModM)).modInverse(N); BigInteger montx = montgomerydomain(a,rsquaremodm,r_i,n); BigInteger monty = montgomerydomain(b,rsquaremodm,r_i,n); BigInteger montz = montgomerydomain(montx,monty,r_i,n); BigInteger Z = montgomerydomain(montz,one,r_i,n); return Z; * @param a * @param R^2 mod M * @param R' * @param m * @return Number that in Montgomery domain private static BigInteger montgomerydomain(biginteger a, BigInteger rsquaremodm, BigInteger r_i,biginteger m) 5

x R' mod M return ((a.multiply(rsquaremodm)).multiply(r_i)).mod(m);//a R^2 mod M * @param m * @return R private static BigInteger ChooseR(BigInteger m) BigInteger R = ONE; BigInteger Result = ONE; for(int i=0;i<m.bitlength();i++) R = R.shiftLeft(1); R = (R.multiply(R)).mod(m); return Result; Encrypt and Decrypt Some Messages to Use Them in Common Modulus To avoid generating a different modulus N = pq for each user one may wish to fix N once for all. The same N is used by all users. A trusted central authority d r vide ser i with a unique pair ei,di r m whi h ser i rms a b i key N, ei) and a se ret key N,di). A ciphertext C = m^ea mod N indented for Alice cannot decrypted by Bob since Bob does not possess da. However, this is incorrect and resulting the system is insecure. Bob can use his own exponents eb and db t a t r the m d s N. On e N is a t red B b an re ver A i e s rivate key da rom her public key ea. This observation, due to Simmons, shows that an RSA modulus should never be used by more than one entity. Let s server send Alice that ciphered message: Let s server send B b that i hered message Then it can be sait that: Then calculate: Therefore, obtaining the message without factoring the modulus is possible. 6

Following Code simulates that Server send same message with same MODULUS, and Oscar listens the encrypted messages of Alice and Bob. Althoug he only knows public keys of the Alice and Bob, he can listen whatever Server tells to Alice and Bob: Results are shown first, Server Says : Hello Alice and Bob How Are You Today I have a Secret Message Do not Tell To Oscar message: Hello message: 310939249775 encryptbirol: 98209189237204485507999883982020794962 decryptbirol: 310939249775 Alice's decrypted Message: Hello encryptbirol: 135785735749386095924839275936215343789 decryptbirol: 310939249775 Bob's DecryptedMessage: Hello Oscar Listens: 310939249775 Oscar Listens: Hello message: Alice and Bob message: 5183382351078682970063789780834 encryptbirol: 164376045300816567038492641461653725618 decryptbirol: 5183382351078682970063789780834 Alice's decrypted Message: Alice and Bob encryptbirol: 43834413395172575368159569342882339208 decryptbirol: 5183382351078682970063789780834 Bob's DecryptedMessage: Alice and Bob Oscar Listens: 5183382351078682970063789780834 Oscar Listens: Alice and Bob 7

message: How Are You message: 87569039178661263994089333 encryptbirol: 126807372247174814540926816854539372824 decryptbirol: 87569039178661263994089333 Alice's decrypted Message: How Are You encryptbirol: 80658951479820665895495471456183523727 decryptbirol: 87569039178661263994089333 Bob's DecryptedMessage: How Are You Oscar Listens: 87569039178661263994089333 Oscar Listens: How Are You message: Today message: 362646102393 encryptbirol: 34023762703651117042092499307410100018 decryptbirol: 362646102393 Alice's decrypted Message: Today encryptbirol: 30018238810529919888647133449633986888 decryptbirol: 362646102393 Bob's DecryptedMessage: Today Oscar Listens: 362646102393 Oscar Listens: Today message: I have a message: 5269326331830935649 encryptbirol: 106094465012213434654852287538551019309 decryptbirol: 5269326331830935649 Alice's decrypted Message: I have a 8

encryptbirol: 131163760962509158965120466736828435387 decryptbirol: 5269326331830935649 Bob's DecryptedMessage: I have a Oscar Listens: 5269326331830935649 Oscar Listens: I have a message: Secret Message message: 1691472818829646257224612891944805 encryptbirol: 145088680795590543245158393151662942323 decryptbirol: 1691472818829646257224612891944805 Alice's decrypted Message: Secret Message encryptbirol: 37109704294308960746762604533697753260 decryptbirol: 1691472818829646257224612891944805 Bob's DecryptedMessage: Secret Message Oscar Listens: 1691472818829646257224612891944805 Oscar Listens: Secret Message message: Do not Tell message: 82731736666910421995056236 encryptbirol: 29146659982952700058990114066210527694 decryptbirol: 82731736666910421995056236 Alice's decrypted Message: Do not Tell encryptbirol: 151156468889118027219168735445819145313 decryptbirol: 82731736666910421995056236 Bob's DecryptedMessage: Do not Tell Oscar Listens: 82731736666910421995056236 Oscar Listens: Do not Tell message: To Oscar message: 6084117147211227506 9

encryptbirol: 147804044953158052305695490182095670746 decryptbirol: 6084117147211227506 Alice's decrypted Message: To Oscar encryptbirol: 17294922720891776962503493992740530048 decryptbirol: 6084117147211227506 Bob's DecryptedMessage: To Oscar Oscar Listens: 6084117147211227506 Oscar Listens: To Oscar package RSA; import java.math.biginteger; import java.security.securerandom; public class Main private final static BigInteger ONE = new BigInteger("1"); private static final int Alice = 1; private static final int Bob = 2; static SecureRandom random = new SecureRandom(); static BigInteger privatekey; static BigInteger publickey; static BigInteger modulus; public static void main(string[] args) BigInteger message, encryptedmessagealice,decryptedmessagealice,encryptedmessagebob,decryptedmessagebo b; //message = new BigInteger(128,random); String testmessage = "How"; byte[] testmessagebytes = testmessage.getbytes(); BigInteger testmessageinteger = new BigInteger(testMessageBytes); //// create message by converting string to integer // String s = "test"; // byte[] bytes = s.getbytes(); // BigInteger message = new BigInteger(s); System.out.println("message: System.out.println("message: " + testmessage); " + testmessageinteger); BigInteger AlicesKey = GenerateKeys(128,Alice); encryptedmessagealice = encryptbirol(testmessageinteger); System.out.println("Alice's Encrypted Message: " +new String(encryptedMessageAlice.toByteArray())); 10

decryptedmessagealice = decryptbirol(encryptedmessagealice); System.out.println("Alice's decrypted Message: " + new String(decryptedMessageAlice.toByteArray())); BigInteger BobsKey = GenerateKeys(128,Bob); encryptedmessagebob = encryptbirol(testmessageinteger); System.out.println("Bob's EncryptedMessage: " +new String(encryptedMessageBob.toByteArray())); decryptedmessagebob = decryptbirol(encryptedmessagebob); System.out.println("Bob's DecryptedMessage: " + new String(decryptedMessageBob.toByteArray())); System.out.println(""); BigInteger d = AlicesKey.modInverse(BobsKey); BigInteger e = (d.multiply(aliceskey).subtract(one)).divide(bobskey); BigInteger Y1 = encryptedmessagealice.pow(d.intvalue()).mod(modulus); BigInteger Y2 = encryptedmessagebob.pow(e.intvalue()).modinverse(modulus); BigInteger OscarListens = Y1.multiply(Y2).mod(modulus); System.out.println("Oscar Listens: " + OscarListens); System.out.println("Oscar Listens: " + new String(OscarListens.toByteArray())); * @param i * @param alice2 */ private static BigInteger GenerateKeys(int N, int index) if(index == Alice) // choose two primes - p and q BigInteger p = new BigInteger("14545081761063098339");//BigInteger.probablePrime(N/2, random); BigInteger q = new BigInteger("12070297673976155981");//BigInteger.probablePrime(N/2,random); // calculate phi BigInteger phi = (p.subtract(one)).multiply(q.subtract(one)); //calculate modulus modulus = p.multiply(q); //choose a public key e w.r.t phi publickey = new BigInteger("11"); // 2^16 +1; privatekey = publickey.modinverse(phi); System.out.println( ""); //System.out.println( "Alice's p: " + p ); //System.out.println( "Alice's q: " + q ); System.out.println( "Alice's modulus: " + modulus ); System.out.println( "Alice's publickey: " + publickey ); System.out.println( "Alice's privatekey: "+ privatekey ); System.out.println( ""); return publickey; 11

else if(index == Bob) // choose two primes - p and q BigInteger p = new BigInteger("14545081761063098339");//BigInteger.probablePrime(N/2, random); BigInteger q = new BigInteger("12070297673976155981");//BigInteger.probablePrime(N/2,random); // calculate phi BigInteger phi = (p.subtract(one)).multiply(q.subtract(one)); //calculate modulus modulus = p.multiply(q); //choose a public key e w.r.t phi publickey = new BigInteger("13"); // 2^16 +1; privatekey = publickey.modinverse(phi); else System.out.println( ""); //System.out.println( "Bob's p: " + p ); //System.out.println( "Bob's q: " + q ); System.out.println( "Bob's modulus: " + modulus ); System.out.println( "Bob's publickey: " + publickey ); System.out.println( "Bob's privatekey: "+ privatekey ); System.out.println( ""); return publickey; throw new IllegalArgumentException(); * @param message * @param exponent. * @param n modulo. * @return message^exponent mod modulus. public static BigInteger modulopower(biginteger message, BigInteger exponent, BigInteger modulus) BigInteger r = ONE; /*for(int i=exponent.bitlength()-1; i>=0; i--) r = (r.multiply(r)).mod(modulus); if (exponent.testbit(i)) r = (r.multiply(message)).mod(modulus); */ for(int i=exponent.bitlength()-1; i>=0; i--) r = montgomerymult(r,r,modulus); if (exponent.testbit(i)) 12

r = montgomerymult(r, message, modulus);//(r.multiply(message)).mod(modulus); return r; * @param N integer * @creates key public static void GenerateKeys(int N) // choose two primes - p and q BigInteger p = new BigInteger("14545081761063098339");//BigInteger.probablePrime(N/2, random); BigInteger q = new BigInteger("12070297673976155981");//BigInteger.probablePrime(N/2,random); // calculate phi BigInteger phi = (p.subtract(one)).multiply(q.subtract(one)); //calculate modulus modulus = p.multiply(q); //choose a public key e w.r.t phi publickey = new BigInteger("65537"); // 2^16 +1; privatekey = publickey.modinverse(phi); System.out.println( "p: " + p ); System.out.println( "q: " + q ); System.out.println( "modulus: " + modulus ); System.out.println( "publickey: " + publickey ); System.out.println( "privatekey: "+ privatekey ); * @param message * @return encrypted message public static BigInteger encryptbirol(biginteger message) BigInteger result = modulopower(message,publickey,modulus); System.out.println("encryptBirol: " + result); return result; * @param encrypted message * @return decrypted message public static BigInteger decryptbirol(biginteger encryptedmessage) BigInteger result = modulopower(encryptedmessage, privatekey, modulus); System.out.println("decryptBirol: " + result); return result; * @param A * @param B. 13

* @param N. * @return C = A x B mod N private static BigInteger montgomerymult(biginteger A, BigInteger B, BigInteger N) BigInteger RSquareModM = ChooseR(N); BigInteger R_I = (RSquareModM.multiply(RSquareModM)).modInverse(N); BigInteger montx = montgomerydomain(a,rsquaremodm,r_i,n); BigInteger monty = montgomerydomain(b,rsquaremodm,r_i,n); BigInteger montz = montgomerydomain(montx,monty,r_i,n); BigInteger Z = montgomerydomain(montz,one,r_i,n); return Z; * @param a * @param R^2 mod M * @param R' * @param m * @return Number that in Montgomery domain private static BigInteger montgomerydomain(biginteger a, BigInteger rsquaremodm, BigInteger r_i,biginteger m) return ((a.multiply(rsquaremodm)).multiply(r_i)).mod(m);//a R^2 mod M x R' mod M * @param m * @return R private static BigInteger ChooseR(BigInteger m) BigInteger R = ONE; BigInteger Result = ONE; for(int i=0;i<m.bitlength();i++) R = R.shiftLeft(1); R = (R.multiply(R)).mod(m); return Result; 14