Взлом Vigenere cipher — различия между версиями

Материал из InformationSecurity WIKI
Перейти к: навигация, поиск
м (Скрипты)
м
 
(не показаны 3 промежуточные версии этого же участника)
Строка 1: Строка 1:
 +
Является производным шифром от шифра Цезаря.
 +
[[Категория:Crypto]]
 +
==Где часто используется==
  
  
=Где часто используется=
+
==Скрипты==
  
 
+
===python===
=Скрипты=
+
====encrypt====
 
 
==python==
 
===encrypt===
 
 
<syntaxhighlight lang="python" line>
 
<syntaxhighlight lang="python" line>
 
def encryption(plaintext, keyword):
 
def encryption(plaintext, keyword):
Строка 21: Строка 21:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===decrypt===
+
====decrypt====
 
<syntaxhighlight lang="python" line>
 
<syntaxhighlight lang="python" line>
 
def decrypt(key, ciphertext):
 
def decrypt(key, ciphertext):
Строка 34: Строка 34:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==perl==
+
===perl===
  
==ruby==
+
===ruby===
 
<syntaxhighlight lang="ruby" line>
 
<syntaxhighlight lang="ruby" line>
 
module VigenereCipher
 
module VigenereCipher
Строка 64: Строка 64:
  
  
==Java==
+
===Java===
===encrypt===
+
====encrypt====
 
<syntaxhighlight lang="ruby" line>
 
<syntaxhighlight lang="ruby" line>
 
     static String encrypt(String text, final String key) {
 
     static String encrypt(String text, final String key) {
Строка 79: Строка 79:
 
     }
 
     }
 
</syntaxhighlight>
 
</syntaxhighlight>
===decrypt===
+
====decrypt====
 
<syntaxhighlight lang="ruby" line>
 
<syntaxhighlight lang="ruby" line>
 
     static String decrypt(String text, final String key) {
 
     static String decrypt(String text, final String key) {
Строка 93: Строка 93:
 
     }
 
     }
 
</syntaxhighlight>
 
</syntaxhighlight>
==C/C++==
+
===C/C++===
  
=Утилиты=
+
==Утилиты==
  
 
https://www.cryptool.org/ - одна из лучших утилит для криптографии
 
https://www.cryptool.org/ - одна из лучших утилит для криптографии
  
=Райтапы=
+
==Райтапы==
 +
 
 +
https://github.com/ctfs/write-ups-2014/tree/master/defkthon-ctf/crypto-100 - DEFKTHON CTF: Crypto 100
 +
 
 +
 
 +
http://0xa.li/th3jackers-2015-ctf-crypto200-writeup/ - Codegate CTF 2011 Crypto 200
 +
 
 +
 
 +
http://www.nobbd.de/blog/artikel.php?titel=write-up-Ekoparty-CTF---Crypto-50-100-200 - Crypto 100
 +
 
 +
==Ссылки==
 +
 
 +
https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher - официальная вики статья
 +
 
 +
 
 +
http://www.counton.org/explorer/codebreaking/vigenere-cipher.php - один из калькуляторов
 +
 
  
 +
http://planetcalc.ru/2468/ - русский вариант шифра виженера
  
  
=Ссылки=
+
http://planetcalc.com/2468/ - еще один калькулятор

Текущая версия на 13:11, 2 июня 2016

Является производным шифром от шифра Цезаря.

Где часто используется

Скрипты

python

encrypt

 1 def encryption(plaintext, keyword):
 2     txt_len = len(plaintext)
 3     keyword *= txt_len // len(keyword) + 1
 4     keyword = keyword[:txt_len]
 5     encoded = ""
 6     for c in range(txt_len):
 7         newchar = ord(plaintext[c]) + ord(keyword[c]) - 194
 8         newchar %= 25
 9         encoded += chr(newchar + 97)
10     return encoded

decrypt

1 def decrypt(key, ciphertext):
2     from itertools import cycle
3     ALPHA = 'abcdefghijklmnopqrstuvwxyz'
4     pairs = zip(ciphertext, cycle(key))
5     result = ''
6     for pair in pairs:
7         total = reduce(lambda x, y: ALPHA.index(x) - ALPHA.index(y), pair)
8         result += ALPHA[total % 26]
9     return result

perl

ruby

 1 module VigenereCipher
 2  
 3   BASE = 'A'.ord
 4   SIZE = 'Z'.ord - BASE + 1
 5  
 6   def encrypt(text, key)
 7     crypt(text, key, :+)
 8   end
 9  
10   def decrypt(text, key)
11     crypt(text, key, :-)
12   end
13  
14   def crypt(text, key, dir)
15     text = text.upcase.gsub(/[^A-Z]/, '')
16     key_iterator = key.upcase.gsub(/[^A-Z]/, '').chars.map{|c| c.ord - BASE}.cycle
17     text.each_char.inject('') do |ciphertext, char|
18       offset = key_iterator.next
19       ciphertext << ((char.ord - BASE).send(dir, offset) % SIZE + BASE).chr
20     end
21   end
22  
23 end


Java

encrypt

 1     static String encrypt(String text, final String key) {
 2         String res = "";
 3         text = text.toUpperCase();
 4         for (int i = 0, j = 0; i < text.length(); i++) {
 5             char c = text.charAt(i);
 6             if (c < 'A' || c > 'Z') continue;
 7             res += (char)((c + key.charAt(j) - 2 * 'A') % 26 + 'A');
 8             j = ++j % key.length();
 9         }
10         return res;
11     }

decrypt

 1     static String decrypt(String text, final String key) {
 2         String res = "";
 3         text = text.toUpperCase();
 4         for (int i = 0, j = 0; i < text.length(); i++) {
 5             char c = text.charAt(i);
 6             if (c < 'A' || c > 'Z') continue;
 7             res += (char)((c - key.charAt(j) + 26) % 26 + 'A');
 8             j = ++j % key.length();
 9         }
10         return res;
11     }

C/C++

Утилиты

https://www.cryptool.org/ - одна из лучших утилит для криптографии

Райтапы

https://github.com/ctfs/write-ups-2014/tree/master/defkthon-ctf/crypto-100 - DEFKTHON CTF: Crypto 100


http://0xa.li/th3jackers-2015-ctf-crypto200-writeup/ - Codegate CTF 2011 Crypto 200


http://www.nobbd.de/blog/artikel.php?titel=write-up-Ekoparty-CTF---Crypto-50-100-200 - Crypto 100

Ссылки

https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher - официальная вики статья


http://www.counton.org/explorer/codebreaking/vigenere-cipher.php - один из калькуляторов


http://planetcalc.ru/2468/ - русский вариант шифра виженера


http://planetcalc.com/2468/ - еще один калькулятор