Created
August 25, 2013 13:56
-
-
Save canerbasaran/6333974 to your computer and use it in GitHub Desktop.
Türkçe Vigenere Şifreleme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# Turkce Vigenere Sifreleme | |
# Copyright 2013 Caner BASARAN | |
# Licensed under the GNU General Public License, version 2. | |
# See the file http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt | |
HARFLER = u'ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ' | |
HARFDONUSUM = [(u'i', u'İ'), (u'ğ', u'Ğ'), (u'ü', u'Ü'), (u'ş', u'Ş'), (u'ö', u'Ö'), (u'ç', u'Ç'), (u'ı', u'I')] | |
def buyult(s): | |
for x, y in HARFDONUSUM: | |
s = s.replace(x, y) | |
return s.upper() | |
def kucult(s): | |
for x, y in HARFDONUSUM: | |
s = s.replace(y, x) | |
return s.lower() | |
def iletiDonustur(anahtar, ileti, kip): | |
donusturulmus = [] | |
anahtarIndex = 0 | |
anahtar = buyult(anahtar) | |
for harf in ileti: | |
num = HARFLER.find(buyult(harf)) | |
if num != -1: | |
if kip == 'sifrele': | |
num += HARFLER.find(anahtar[anahtarIndex]) | |
elif kip == 'desifrele': | |
num -= HARFLER.find(anahtar[anahtarIndex]) | |
num %= len(HARFLER) | |
if harf.isupper(): | |
donusturulmus.append(HARFLER[num]) | |
elif harf.islower(): | |
donusturulmus.append(kucult(HARFLER[num])) | |
anahtarIndex += 1 | |
if anahtarIndex == len(anahtar): | |
anahtarIndex = 0 | |
else: | |
donusturulmus.append(harf) | |
return ''.join(donusturulmus) | |
print iletiDonustur(u'Cemil Meriç', u"Sebfy ıepcplöhry mıfep mçie gişkmr lnn çet: mısisşn dküaşşı.", 'desifrele') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment