Sezir usuli ni python dasturlash tilida: def encrypt(text,s)



Download 1,87 Mb.
Sana08.12.2022
Hajmi1,87 Mb.
#881171


SEZIR USULI NI PYTHON Dasturlash tilida:

def encrypt(text,s):


result = ""
# traverse text
for i in range(len(text)):
char = text[i]
# Encrypt uppercase characters
if (char.isupper()):
result += chr((ord(char) + s-65) % 26 + 65)
# Encrypt lowercase characters
else:
result += chr((ord(char) + s - 97) % 26 + 97)
return result
#check the above function
text =input("textni kiriting: ")
s=int(input("nechta raqamga surush kerak: "))
print ("Text : " + text)
print ("Shift : " + str(s))
print ("Cipher: " + encrypt(text,s))

SEZIR SHEFIRLASH ALGORITMNI RASMIY SAYT NATIJALARI:



MENIKI BILAN BIR XIL.

VERNAM SHIFRLASH

def vernam(key,message):
message = str(message)
m = message.upper().replace(" ","") # Convert to upper case, remove whitespace
encrypt = ""
try:
key = int(key) # if the key value is not a number, then run with key = 0
except ValueError:
key = 0
for i in range(len(m)):
letter = ord(m[i])-65 # Letters now range 0-25
letter = (letter + key)%25 # Alphanumeric + key mod 25 = 0-25
letter +=65

encrypt = encrypt + chr(letter) # Concatenate message


return encrypt

""" * TEST CASES * """


print(vernam(9,"hello world"))

Vijiner shifrlash


def generateKey(string, key):
key = list(key)
if len(string) == len(key):
return(key)
else:
for i in range(len(string) -
len(key)):
key.append(key[i % len(key)])
return("" . join(key))

def cipherText(string, key):
cipher_text = []
for i in range(len(string)):
x = (ord(string[i]) +
ord(key[i])) % 26
x += ord('A')
cipher_text.append(chr(x))
return("" . join(cipher_text))

def originalText(cipher_text, key):


orig_text = []
for i in range(len(cipher_text)):
x = (ord(cipher_text[i]) -
ord(key[i]) + 26) % 26
x += ord('A')
orig_text.append(chr(x))
return("" . join(orig_text))

if __name__ == "__main__":
string = input('matnni kiriting: ')
keyword =input("kalitni kiriting: ")
key = generateKey(string, keyword)
cipher_text = cipherText(string,key)
print("Shifrlangan text :", cipher_text)
print("Original Text :",
originalText(cipher_text, key))


Download 1,87 Mb.

Do'stlaringiz bilan baham:




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