Skip to content

Instantly share code, notes, and snippets.

@ktprezes
Last active March 1, 2021 10:08
Show Gist options
  • Save ktprezes/6e38dbc2f3df4a201db51d2f46803d61 to your computer and use it in GitHub Desktop.
Save ktprezes/6e38dbc2f3df4a201db51d2f46803d61 to your computer and use it in GitHub Desktop.
Python - Szyfr Cezara - przykładowa implementacja - (Caesar cipher naive implementation)
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# Szyfr Cezara - przykładowa implementacja
# dla zdekodowania zaszyfrowanego tekstu trzeba podać przesunięcie o przeciwnym znaku
# np: kodowanie z przesunięciem '7', to dekodowanie - z przesunięciem '-7'
# lub kodowanie z przesunięciem '-100', to dekodowanie - z przesunięciem '100'
alfabet = 'aAąĄbBcCćĆdDeEęĘfFgGhHiIjJkKlLłŁmMnNńŃoOóÓpPqQrRsSśŚtTuUvVwWxXyYzZźŹżŻ'
tekst_we =""
tekst_wy =""
znak =""
przes = 0
indx = 0
while(1):
tekst_we = input("Podaj tekst: ")
if tekst_we == "" :
break
przes = int(input("Podaj przesunięcie: "))
tekst_wy = ""
for znak in tekst_we:
indx = alfabet.find(znak)
if indx != -1 :
tekst_wy += alfabet[ (indx + przes) % len(alfabet) ]
else:
tekst_wy += znak
print("Tekst wyjściowy to: " + tekst_wy)
@Dominika-ctr
Copy link

Jak odszyfrować i zakończyć program?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment