|
Kriptografiya”fanidan loyiha ishi bajardi: Nuraliyev Shuxrat 072-20 Nuriddinov Xusniddin 072-20 toshkent 2023
|
bet | 3/3 | Sana | 13.01.2024 | Hajmi | 0,71 Mb. | | #136773 |
Bog'liq Loyiha ishi
Dastur kodi
import java.math.BigInteger; import java.util.ArrayList; import java.util.List;
public class RSACrypt {
public static BigInteger n = new BigInteger("3521965691682498349894156297871351510003392837134480208222044"
+ "4753957752560806765915557404471872854222134926440656261548716"
+ "5251895509139075621688493447805478090729096096693340629223579"
+ "5059531555148850225316762953811321830535065868925602454064437"
+ "6849173366230815779694365269990430445181132796913932904941185"
+ "478344783047790284034086549612594449881");
public static void main(String[] args) { BigInteger c = new
BigInteger("1946990934266279413917993964398835970466043305162067149027416"
+ "2053008128349816033069247844970800863920955661712219866590366"
+ "9590908102703307250646216395967327417349581565673419272952219"
+ "8445430968778476727718084419319887006224079130320273805411547"
+ "7138201099392091672934450078062438509784548210810385639731494"
+ "7527381565904894782921374911825451607");
BigInteger e = new BigInteger("65537"); List bigIntegers = pFactor();
BigInteger p = bigIntegers.get(0); BigInteger q=bigIntegers.get(1); System.out.println("p = " + p); System.out.println("q = " + q);
BigInteger f=p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE)); BigInteger d = e.modInverse(f);
System.out.println("d = " + d); BigInteger m = c.modPow(d, n); System.out.println("Ochiq matn: " + m);
}
public static List pFactor() { List result=new ArrayList<>();
// P-algoritmini amalga oshirish BigInteger x = new BigInteger("2"); BigInteger y = new BigInteger("2");
BigInteger d = BigInteger.ONE; while (d.equals(BigInteger.ONE)) {
x = f(x, n);
y = f(f(y, n), n);
d = gcd(x.subtract(y).abs(), n);
}
// Faktorlarni chiqarish if (d.equals(n)) {
return null;
}
result.add(d); result.add(n.divide(d)); return result;
}
// Funksiyalarni aniqlash (x*x +1)%N
public static BigInteger f(BigInteger x, BigInteger n) { return x.multiply(x).add(BigInteger.ONE).mod(n);
}
// 2 ta sonning ekubini topadi
public static BigInteger gcd(BigInteger a, BigInteger b) {
if (a.equals(BigInteger.ZERO)) { return b;
}
return gcd(b.mod(a), a);
}
}
|
| |