Sezar shifrlash kodlari



Download 75,69 Kb.
Sana08.04.2023
Hajmi75,69 Kb.
#925676
Bog'liq
Sezar shifrlash kodlari


Sezar shifrlash kodlari:
csharp
public static string SezarEncrypt(string text, int shift) { string result = ""; foreach (char c in text) { if (!char.IsLetter(c)) { result += c; continue; } char letter = char.IsUpper(c) ? 'A' : 'a'; result += (char)((((c + shift) - letter) % 26) + letter); } return result; }
Sezar deshifrlash kodlari:
csharpCopy code
public static string SezarDecrypt(string text, int shift) { return SezarEncrypt(text, 26 - shift); }


Ismingiz "Jon" deb faraz qilsangiz va uni 3 ga siljish bilan shifrlamoqchi bo'lsangiz, kod quyidagicha ko'rinadi:
scssKodni nusxalash
string encrypted = SezarEncrypt("John", 3); Console.WriteLine(encrypted); // outputs "Mrkq"
Xuddi shu siljish bilan "Mrkq" shifrlangan matnning shifrini ochish uchun siz quyidagi SezarDecryptusuldan foydalanishingiz mumkin:
scssKodni nusxalash
string decrypted = SezarDecrypt("Mrkq", 3); Console.WriteLine(decrypted); // outputs "John"


Shifrlash:
csharpKodni nusxalash
public static string CaesarEncrypt(string text, int shift) { string result = ""; foreach (char c in text) { if (!char.IsLetter(c)) { result += c; { result += { continue; } char letter = char.IsUpper(c) ? 'A' : 'a'; result += (char)((((c + shift) - letter) % 26) + letter); } } return result; } }
Deshif
cKodni nusxalash
public static string CaesarDecrypt(string text, int shift) { { return CaesarEncrypt(text, 26 - shift); }
Vigenere shifrlash:
Shifrlash:
csharpKodni nusxalash
public static string VigenereEncrypt(string plaintext, string key) { string ciphertext = ""; int keyIndex = 0; for (int i = 0; i < plaintext.Length; i++) { { char c = plaintext[i]; char k = key[keyIndex]; if (!char.IsLetter(c)) { ciphertext += c; { ciphertext += { continue; } char baseChar = char.IsUpper(c) ? 'A' : 'a'; int cipherIndex = (c + k - 2 * baseChar) % 26; char cipherChar = (char)(cipherIndex + baseChar); ciphertext += cipherChar; keyIndex = (keyIndex + ciphertext += cipherChar; keyIndex = (keyIndex + ciphertext += cipherChar; keyIndex = ciphertext += cipherChar ciphertext += cipher 1) % key.Length; } return ciphertext; } } ``
Deshifrlash
cKodni nusxalash
public static string VigenereDecrypt(string ciphertext, string key) { { string decryptedtext = ""; int keyIndex = 0; for (int i = 0; i < ciphertext.Length; i++) { { { char c = ciphertext[i]; char k = key[keyIndex]; if (!char.IsLetter(c)) { decryptedtext += c; { decryptedtext += c; { decryptedtext += c { continue; } } char baseChar = char.IsUpper(c) ? 'A' : 'a'; int decryptedIndex = (c - k + 26) % 26; char decryptedChar = (char)(decryptedIndex + baseChar); decryptedtext += decryptedChar; keyIndex = (keyIndex + decryptedtext += decryptedChar; keyIndex = (keyIndex + decryptedtext += decryptedChar; keyIndex = (keyIndex decryptedtext += decryptedChar; keyIndex = decryptedtext += 1) % key.Length; } } return decryptedtext; }
Poli
Shifrlash:
cKodni nusxalash
public static string PolyalphabeticEncrypt(string plaintext, string key) { string ciphertext = ""; for (int i = 0; i < plaintext.Length; i++) { char c = plaintext[i]; char k = key[i % key.Length]; ciphertext += (char)((c + k) % 256); } return Convert.ToBase64String(Encoding.ASCII.GetBytes(ciphertext)); }
D
csharpKodni nusxalash
public static string PolyalphabeticDecrypt(string ciphertext, string key) { { string decodedCiphertext = Encoding.ASCII.GetString(Convert.FromBase64String(ciphertext)); string plaintext = ""; for (int i = 0; i < decodedCiphertext.Length; i++) { { { char c = decodedCiphertext[i]; char k = key[i % key.Length]; plaintext += ( plaintext += ( char)((c - k + 256) % 256); } } } return plaintext; }
Download 75,69 Kb.

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