Amaliy ish Mavzu: Elliptik egri chiziqlarda nuqtalarni n lashtirish imkonini beruvchi dasturiy vositani ishlab chiqish. 714-19 โ€“ guruh talabasi Bajardi : Mamatov Sadriddin Tekshirdi: Olimov Iskandar toshkent -2022



Download 169,61 Kb.
bet2/2
Sana14.07.2022
Hajmi169,61 Kb.
#796065
1   2
Bog'liq
1654944111 (1)

Shifrlash


  • ๐‘ = ๐‘š2 ๐‘š๐‘œ๐‘‘ ๐‘ = 400 ๐‘š๐‘œ๐‘‘ 77 = 15 Deshifrlash

๐‘+1

  • ๐‘š๐‘ = ๐‘ โ„4 ๐‘š๐‘œ๐‘‘ ๐‘ = 152 ๐‘š๐‘œ๐‘‘ 7 = 1

  • ๐‘š๐‘ž = ๐‘๐‘ž+1โ„4 ๐‘š๐‘œ๐‘‘ ๐‘ž = 153 ๐‘š๐‘œ๐‘‘ 11 = 9

  • ๐‘ฆ๐‘ โˆ— ๐‘ + ๐‘ฆ๐‘ž โˆ— ๐‘ž = (โˆ’3 โˆ— 7) + (2 โˆ— 11) = 1

  • ๐‘Ÿ1 = (๐‘ฆ๐‘ โˆ— ๐‘ โˆ— ๐‘š๐‘ž + ๐‘ฆ๐‘ž โˆ— ๐‘ž โˆ— ๐‘š๐‘) ๐‘š๐‘œ๐‘‘๐‘ = (โˆ’3 โˆ— 7 โˆ— 9 + 2 โˆ— 11 โˆ—

    1. ๐‘š๐‘œ๐‘‘ 77 = 64

  • ๐‘Ÿ2 = ๐‘ โˆ’ ๐‘Ÿ1 = 77 โˆ’ 64 = 13

  • ๐‘Ÿ3 = (๐‘ฆ๐‘ โˆ— ๐‘ โˆ— ๐‘š๐‘ž โˆ’ ๐‘ฆ๐‘ž โˆ— ๐‘ž โˆ— ๐‘š๐‘) ๐‘š๐‘œ๐‘‘ ๐‘ = (โˆ’3 โˆ— 7 โˆ— 9 โˆ’ 2 โˆ— 11 โˆ—

    1. ๐‘š๐‘œ๐‘‘ 77 = 20

  • ๐‘Ÿ4 = ๐‘ โˆ’ ๐‘Ÿ3 = 77 โˆ’ 20 = 57

package com.company.university;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;

public class RabinCryptosystem {


public static void main(String[] args) {
BigInteger[] key = Cryptography.generateKey(512);
BigInteger n = key[0];
BigInteger p = key[1];
BigInteger q = key[2];
String finalMessage = null;
int i = 1;
String s = "Mamatov";

System.out.println("Junativchi yuborgan habar : " + s);


BigInteger m


= new BigInteger(
s.getBytes(
StandardCharsets.US_ASCII));
BigInteger c = Cryptography.encrypt(m, n);

System.out.println("Shifrlangan habar : " + c);


BigInteger[] m2 = Cryptography.decrypt(c, p, q);


for (BigInteger b : m2) {
String dec = new String(
b.toByteArray(),
StandardCharsets.US_ASCII);
if (dec.equals(s)) {
finalMessage = dec;
}
i++;
}
System.out.println(
"Qabul qilingn habar : "
+ finalMessage);
}
}

Abdumalik Buxoro, [6/11/2022 1:54 PM]


package com.company.university;

// Java program to illustrate


// Process of Rabin Cryptosystem

import java.math.BigInteger;


import java.security.SecureRandom;
import java.util.Random;

class Cryptography {


private static Random r = new SecureRandom();
private static BigInteger TWO = BigInteger.valueOf(2);
private static BigInteger THREE = BigInteger.valueOf(3);
private static BigInteger FOUR = BigInteger.valueOf(4);

public static BigInteger[] generateKey(int bitLength) {


BigInteger p = blumPrime(bitLength / 2);
BigInteger q = blumPrime(bitLength / 2);
BigInteger N = p.multiply(q);
return new BigInteger[]{N, p, q};
}

public static BigInteger encrypt(BigInteger m,


BigInteger N) {
return m.modPow(TWO, N);
}

public static BigInteger[] decrypt(BigInteger c,


BigInteger p,
BigInteger q) {
BigInteger N = p.multiply(q);
BigInteger p1 = c.modPow(p
.add(BigInteger.ONE)
.divide(FOUR),
p);
BigInteger p2 = p.subtract(p1);
BigInteger q1 = c.modPow(q
.add(BigInteger.ONE)
.divide(FOUR),
q);
BigInteger q2 = q.subtract(q1);

BigInteger[] ext = Gcd(p, q);


BigInteger y_p = ext[1];
BigInteger y_q = ext[2];

BigInteger d1 = y_p.multiply(p)


.multiply(q1)
.add(y_q.multiply(q)
.multiply(p1))
.mod(N);
BigInteger d2 = y_p.multiply(p)
.multiply(q2)
.add(y_q.multiply(q)
.multiply(p1))
.mod(N);
BigInteger d3 = y_p.multiply(p)
.multiply(q1)
.add(y_q.multiply(q)
.multiply(p2))
.mod(N);
BigInteger d4 = y_p.multiply(p)
.multiply(q2)
.add(y_q.multiply(q)
.multiply(p2))
.mod(N);

return new BigInteger[]{d1, d2, d3, d4};


}

public static BigInteger[] Gcd(BigInteger a, BigInteger b) {


BigInteger s = BigInteger.ZERO;
BigInteger old_s = BigInteger.ONE;
BigInteger t = BigInteger.ONE;
BigInteger old_t = BigInteger.ZERO;
BigInteger r = b;
BigInteger old_r = a;
while (!r.equals(BigInteger.ZERO)) {
BigInteger q = old_r.divide(r);
BigInteger tr = r;
r = old_r.subtract(q.multiply(r));
old_r = tr;

BigInteger ts = s;


s = old_s.subtract(q.multiply(s));
old_s = ts;

BigInteger tt = t;


t = old_t.subtract(q.multiply(t));
old_t = tt;
}
return new BigInteger[]{old_r, old_s, old_t};
}

public static BigInteger blumPrime(int bitLength) {


BigInteger p;
do {
p = BigInteger.probablePrime(bitLength, r);
} while (!p.mod(FOUR).equals(THREE));
return p;
}
}

import java.math.BigInteger;


import java.nio.charset.Charset;
import java.security.SecureRandom;
import java.util.Random;

class Cryptography {


private static Random r = new SecureRandom();
private static BigInteger TWO = BigInteger.valueOf(2);
private static BigInteger THREE = BigInteger.valueOf(3);
private static BigInteger FOUR = BigInteger.valueOf(4);

public static BigInteger[] generateKey(int bitLength)


{
BigInteger p = blumPrime(bitLength / 2);
BigInteger q = blumPrime(bitLength / 2);
BigInteger N = p.multiply(q);
return new BigInteger[] { N, p, q };
}

public static BigInteger encrypt(BigInteger m,


BigInteger N)
{
return m.modPow(TWO, N);
}

public static BigInteger[] decrypt(BigInteger c,


BigInteger p,
BigInteger q)
{
BigInteger N = p.multiply(q);
BigInteger p1 = c.modPow(p
.add(BigInteger.ONE)
.divide(FOUR),
p);
BigInteger p2 = p.subtract(p1);
BigInteger q1 = c.modPow(q
.add(BigInteger.ONE)
.divide(FOUR),
q);
BigInteger q2 = q.subtract(q1);

BigInteger[] ext = Gcd(p, q);


BigInteger y_p = ext[1];
BigInteger y_q = ext[2];

BigInteger d1 = y_p.multiply(p)


.multiply(q1)
.add(y_q.multiply(q)
.multiply(p1))
.mod(N);
BigInteger d2 = y_p.multiply(p)
.multiply(q2)
.add(y_q.multiply(q)
.multiply(p1))
.mod(N);
BigInteger d3 = y_p.multiply(p)
.multiply(q1)
.add(y_q.multiply(q)
.multiply(p2))
.mod(N);
BigInteger d4 = y_p.multiply(p)
.multiply(q2)
.add(y_q.multiply(q)
.multiply(p2))
.mod(N);

return new BigInteger[] { d1, d2, d3, d4 };


}

public static BigInteger[] Gcd(BigInteger a, BigInteger b)


{
BigInteger s = BigInteger.ZERO;
BigInteger old_s = BigInteger.ONE;
BigInteger t = BigInteger.ONE;
BigInteger old_t = BigInteger.ZERO;
BigInteger r = b;
BigInteger old_r = a;
while (!r.equals(BigInteger.ZERO)) {
BigInteger q = old_r.divide(r);
BigInteger tr = r;
r = old_r.subtract(q.multiply(r));
old_r = tr;

BigInteger ts = s;


s = old_s.subtract(q.multiply(s));
old_s = ts;

BigInteger tt = t;


t = old_t.subtract(q.multiply(t));
old_t = tt;
}
return new BigInteger[] { old_r, old_s, old_t };
}

public static BigInteger blumPrime(int bitLength)


{
BigInteger p;
do {
p = BigInteger.probablePrime(bitLength, r);
} while (!p.mod(FOUR).equals(THREE));
return p;
}
}
public class RabinCryptosystem {
public static void main(String[] args)
{
BigInteger[] key = Cryptography.generateKey(512);
BigInteger n = key[0];
BigInteger p = key[1];
BigInteger q = key[2];
String finalMessage = null;
int i = 1;
String s = "Mamatov";

System.out.println("Junatuvchi junatgan habar : " + s);


BigInteger m


= new BigInteger(
s.getBytes(
Charset.forName("ascii")));
BigInteger c = Cryptography.encrypt(m, n);

System.out.println("Shifrlangan xabar : " + c);


BigInteger[] m2 = Cryptography.decrypt(c, p, q);


for (BigInteger b : m2) {
String dec = new String(
b.toByteArray(),
Charset.forName("ascii"));
if (dec.equals(s)) {
finalMessage = dec;
}
i++;
}
System.out.println(
"Qabul qiluvchidan qabul qilingan habar : "
+ finalMessage);
}
}



Download 169,61 Kb.

Do'stlaringiz bilan baham:
1   2




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
ัŽั€ั‚ะดะฐ ั‚ะฐะฝั‚ะฐะฝะฐ
ะ‘ะพา“ะดะฐ ะฑะธั‚ะณะฐะฝ
ะ‘ัƒะณัƒะฝ ัŽั€ั‚ะดะฐ
ะญัˆะธั‚ะณะฐะฝะปะฐั€ ะถะธะปะผะฐะฝะณะปะฐั€
ะญัˆะธั‚ะผะฐะดะธะผ ะดะตะผะฐะฝะณะปะฐั€
ะฑะธั‚ะณะฐะฝ ะฑะพะดะพะผะปะฐั€
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan boโ€™yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
boโ€™yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish