67
RSA tizimi bo„yicha loyiha keyslarini yaratish va talabalar bilimini
tekshirish usullari.
Ishdan maqsad: R
SA shifrlash algoritmi ishlash prinsipini o‗rganish va
uning dasturlash tillarida loyihalash.
RSA kriptografik algoritimning python dasturlash tilida yozilgan
dasturi:
#1-Qadam. RSA shifrlash algoritmi uchun 200 dan kam bo„lmaga p va
q sonlarini kiriting!
print('p tub son kiriting! p:=')
p=int(input())
print('q tub son kiriting! q:=')
q=int(input())
# n ni aniqlaymiz
n=p*q
print('n=',n)
#3-Qadam
#Eyler funksiyasi m ni aniqlaymiz.
m=(p-1)*(q-1)
print('m=',m)
#4-Qadam
#
m bilan o„zoro tub bo„lgan {t} sonlar to„plami aniqlanadi
t=[]
for i in range (1,m+1):
k=0
for j in range (1,i+1):
if i%j==0:
k=k+1
if k==2:
if m%i!=0:
t.append(i)
print("d=",t)
# {t} sonlar to„plamidan tasodifiy d-DESHIFRLASH kaliti tanlanadi
import random
d=random.choice(t)
print("Deifrlash kaliti tanlanadi(d;n):=",d,";",n)
#5-Qadam
68
# (e*d mod m=1) tenglamadan e-SHIFRLASH kaliti topiladi
e=1
while (e*d%m!=1)or(e==d):
e=e+1
print("Sifrlash kaliti (e;n):=",e,";",n)
#Ochiq matn shifrLASH JARAYONI
shifrmatn=[]
s=input("Ochiq matn kiriting:")
s1="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
l=len(s)
for t in range (0,l):
x = s1.index(s[t])+1
y=x**e%n
shifrmatn.append(y)
print(x," ",end="")
print("shifrmatn:",shifrmatn)
Dostları ilə paylaş: