Пример #1
0
def decrypt(c, key):
    rotation = lowercase.find(key)

    if c in uppercase:
        index = uppercase.find(c)
        index -= rotation
        return uppercase[index % 26]

    elif c in lowercase:
        index = lowercase.find(c)
        index -= rotation
        return lowercase[index % 26]

    else:
        return c
Пример #2
0
def vigenereEncrypt(plain_text, key):
    cipher_text = ''
    keyStep = cycle([
        lowercase.find(k) if lowercase.find(k) != -1 else 0
        for k in key.lower()
    ])
    for letter in plain_text:
        if letter in lowercase:
            cipher_text += lowercase[(lowercase.find(letter) + next(keyStep)) %
                                     26]
        elif letter in uppercase:
            cipher_text += uppercase[(uppercase.find(letter) + next(keyStep)) %
                                     26]
        else:
            cipher_text += letter
    return cipher_text
Пример #3
0
def next_pass(input):
    last_letter = input[-1]
    next_letter = lc[(lc.find(last_letter) + 1) % len(lc)]
    if next_letter == 'a':
        return next_pass(input[:-1]) + next_letter
    else:
        return input[:-1] + next_letter
Пример #4
0
def fn_csr(n, s_csr):
    s_out = ''
    for x in xrange(len(s_csr)):
        if s_csr[x].isalpha():
            if s_csr[x].islower():
                s_out += lowercase[(lowercase.find(s_csr[x]) + n) % 26]
            else:
                s_out += uppercase[(uppercase.find(s_csr[x]) + n) % 26]
        else:
            s_out += s_csr[x]
    return s_out
Пример #5
0
	def shift(self, text, key):
		result = ""
		for x in range(len(text)):
			if text[x].isalpha():
				if text[x].islower():
					result += lowercase[(lowercase.find(text[x]) + key) % 26]
				else:
					result += uppercase[(uppercase.find(text[x]) + key) % 26]
			else:
				result += text[x]

		return result
Пример #6
0
def decrypt(c,rotation):
 ret = ""
 for i in c:
  if i in uppercase:
   index = uppercase.find(i)
   index += rotation
   ret += uppercase[index % 26]
  elif i in lowercase:
   index = lowercase.find(i)
   index += rotation
   ret += lowercase[index % 26]
  else :
   ret +=i

 return ret
Пример #7
0
	def brute(self, text):
		result = []

		for i in range(26):
			results = ""
			for x in range(len(text)):
				if text[x].isalpha():
					if text[x].islower():
						results += lowercase[(lowercase.find(text[x]) + i) % 26]
					else:
						results += uppercase[(uppercase.find(text[x]) + i) % 26]
				else:
					results += text[x]
			
			result.append(results)

		return result
#importa biblioteca onde permite pegar o nome do arquivo
import sys
#importa letras minusculas armazenando no lc
from string import lowercase as lc
#importa o arquivo como 1 argumento
file = open(sys.argv[1], 'r').read().lower()

#gera um lop onde testa todas as possibilidades alfabeticas
for key in xrange(1, 26):
    result = ''  #resultado vazio sempre que começa um loop
    print 'key:', key  #imprime a chave
    for lt in file:  #loop para testar todo o arquivo guarda em lt
        if lt in lc:
            idx = lc.find(lt)  #guarda as letras em um index
            idx = (idx - key) % 26  #subtrai o index - a chave do loop acima
            result += lc[idx]  #guarda o resultado
        else:
            result += lt  #ignora espaços vazio

    print result,  #imprime resultado
Пример #9
0
#!/usr/bin/python

import sys
from string import lowercase as alfabeth

file = open(sys.argv[1], 'r').read().lower()
key = sys.argv[2].lower()
mode = sys.argv[3]
result = ''
keyidx = 0

for letras in file:
    if letras in alfabeth:
        idx = alfabeth.find(letras)
        if mode == 'enc':
            idx += alfabeth.find(key[keyidx % len(key)])
        elif mode == 'dec':
            idx -= alfabeth.find(key[keyidx % len(key)])
        result += alfabeth[idx % 26]
    else:
        result += letras
print(result, )
Пример #10
0
from string import lowercase


shift_char = lambda c, shift: lowercase[
    (lowercase.find(c) + shift) % len(lowercase)]
Пример #11
0
#!/usr/bin/python

import sys
from string import lowercase as alfabeth

file = open(sys.argv[1], 'r').read().lower()

for key in range(1, 26):
    result = ''
    for letras in file:
        if letras in alfabeth:
            idx = alfabeth.find(letras)
            idx = (idx - key) % 26
            result += alfabeth[idx]
        else:
            result += letras
    print(
        'Key:',
        key,
        '|',
        result,
    )
Пример #12
0
#!/usr/bin/env python
#Programa para criptografar e descriptografar arquivo txt,essa e a criptografia de cesar

import sys
from string import lowercase as lc

file = open(sys.argv[1], 'r').read().lower()
key = int(sys.argv[2])
mode = sys.argv[3]

result = ''

for lt in file:
    if lt in lc:
        idx = lc.find(lt)
        if mode == 'enc':
            idx = (idx + key) % 26
        elif mode == 'dec':
            idx = (idx - key) % 26
        result += lc[idx]
    else:
        result += lt
print result,
Пример #13
0
import sys

from string import lowercase as lc

file = open(sys.argv[1], 'r').read().lower()
key = sys.argv[2].lower()
mode = sys.argv[3]

result = ''
keyidx = 0

for lt in file:
    if lt in lc:
        idx = lc.find(lt)
        if mode == 'enc':
            idx += lc.find(key[keyidx % len(key)])
        elif mode == 'dec':
            idx -= lc.find(key[keyidx % len(key)])
        result += lc[idx % 26]
    else:
        result += lt
print result,
Пример #14
0
#importa sys que permite argumento no cmd
import sys
#importa letras minusculas
from string import lowercase as lc

file = open(sys.argv[1], 'r').read().lower()  #1 argumento= nome do arquivo
key = sys.argv[2].lower()  #2 argumento = palavra chave tudo junto e misturado
mode = sys.argv[3]  #modo encripta ou descripta

result = ''  #resultado vazio
keyidx = 0  #lembra qual posicao a palavra esta.
#ex1:
#gabrielemuitolegalporquesim
#senhasenhasenhasenhasenhase
for lt in file:  #ler todo o arquivo
    if lt in lc:  #le todas as letras
        idx = lc.find(lt)  #guarda as letras no lc
        if mode == 'enc':
            idx += lc.find(
                key[keyidx % len(key)]
            )  # preenche a frase a ser criptografada com a chave, deixando a frase e a chave com o mesmo numero de palavras repetindo a chave sempre ate o final da frase. ex1 ali  em cima.
        elif mode == 'dec':
            idx -= lc.find(key[keyidx %
                               len(key)])  #faz o inverso do texto ali em cima.
        result += lc[
            idx %
            26]  #se o resultado for maior que 26, ele volta para zero e soma o que sobrou. ex: 32 = 26 + 6 result = 6.
    else:
        result += lt  #ignora espaços
print result,  #print result.
Пример #15
0
#!/usr/bin/python

import sys
from string import lowercase as alfabeth

file = open(sys.argv[1], 'r').read().lower()
key = int(sys.argv[2])
mode = sys.argv[3]
result = ''

for lt in file:
    if lt in alfabeth:
        idx = alfabeth.find(lt)
        if mode == 'enc':
            idx = (idx + key) % 26
        elif mode == 'dec':
            idx = (idx - key) % 26
        result += alfabeth[idx]
    else:
        result += lt
print(result, )
Пример #16
0
from string import lowercase

shift_char = lambda c, shift: lowercase[
    (lowercase.find(c) + shift) % len(lowercase)]
Пример #17
0
def fn_main():
    print author
    halah = argparse.ArgumentParser(description=' [+] Tools to Encoding, Decoding and Hashing [+]')
    halah.add_argument('str', help='Strings')
    halah.add_argument('-e', action='store_true', help='encode strings')
    halah.add_argument('-d', action='store_true', help='decode strings')
    halah.add_argument('-brute', action='store_true', help='Bruteforce char')
    halah.add_argument('-key', type=int, action='store', help='Key for char caessar cipher')
    halah.add_argument('-k', type=str, action='store', help='Key for char xor')
    halah.add_argument('-b64', action='store_true', help='Base64 encryptions')
    halah.add_argument('-b32', action='store_true', help='Base32 encryptions')
    halah.add_argument('-b16', action='store_true', help='Base16 encryptions')
    halah.add_argument('-hex', action='store_true', help='Hexadecimal')
    halah.add_argument('-dec', action='store_true', help='Decimal')
    halah.add_argument('-bin', action='store_true', help='Binary')
    halah.add_argument('-rev', action='store_true', help='Reverse Strings')
    halah.add_argument('-rot13', action='store_true', help='ROT 13 Cipher')
    halah.add_argument('-caes', action='store_true', help='Caessar Cipher')
    halah.add_argument('-xor', action='store_true', help='XOR Cipher')
    halah.add_argument('-md5', action='store_true', help='MD5 Hashing')
    halah.add_argument('-sha1', action='store_true', help='SHA1 Hashing')
    halah.add_argument('-sha256', action='store_true', help='SHA256 Hashing')
    halah.add_argument('-sha512', action='store_true', help='SHA512 Hashing')
    wibu = halah.parse_args()

    if wibu.b64 and wibu.e:
        fn_result(base64.b64encode(wibu.str))

    if wibu.b64 and wibu.d:
        try:
            fn_result(base64.b64decode(wibu.str))
        except:
            fn_error('base64')

    if wibu.b32 and wibu.e:
        fn_result(base64.b32encode(wibu.str))

    if wibu.b32 and wibu.d:
        try:
            fn_result(base64.b32decode(wibu.str))
        except:
            fn_error('base32')

    if wibu.b16 and wibu.e:
        fn_result(base64.b16encode(wibu.str))

    if wibu.b16 and wibu.d:
        try:
            fn_result(base64.b16decode(wibu.str))
        except:
            fn_error('base16')

    if wibu.hex and wibu.e:
        fn_result(binascii.hexlify(wibu.str))

    if wibu.hex and wibu.d:
        try:
            fn_result(binascii.unhexlify(wibu.str))
        except:
            fn_error('hexadecimal')

    if wibu.dec and wibu.e:
        fn_result(''.join([str(ord(c)) for c in wibu.str]))

    if wibu.dec and wibu.d:
        try:
            fn_result(re.sub('1?..', lambda m: chr(int(m.group())), wibu.str))
        except:
            fn_error('decimal')

    if wibu.bin and wibu.e:
        fn_result(bin(int(binascii.hexlify(wibu.str), 16)))

    if wibu.bin and wibu.d:
        try:
            fn_result(binascii.unhexlify('%x' % int(wibu.str, 2)))
        except:
            fn_error('binary')

    if wibu.rev:
        fn_result(wibu.str[::-1])

    if wibu.rot13:
        if wibu.rot13 or wibu.e or wibu.d:
            fn_result(wibu.str.encode('rot_13'))

    if wibu.caes and wibu.key:
        en = wibu.str
        n = wibu.key
        hasil = ''
        for x in range(len(en)):
            if en[x].isalpha():
                if en[x].islower():
                    hasil = hasil + lowercase[(lowercase.find(en[x]) + n) % 26]
                else:
                    hasil = hasil + uppercase[(uppercase.find(en[x]) + n) % 26]
            else:
                hasil = hasil + en[x]
        fn_result(hasil)

    if wibu.caes and wibu.brute:
        for i in range(26):
            hasil = ''
            for x in range(len(wibu.str)):
                if wibu.str[x].isalpha():
                    if wibu.str[x].islower():
                        hasil = hasil + lowercase[(lowercase.find(wibu.str[x]) + i) % 26]
                    else:
                        hasil = hasil + uppercase[(uppercase.find(wibu.str[x]) + i) % 26]
                else:
                    hasil = hasil + wibu.str[x]
            print '{} => [+] Result => {}'.format(str(i), hasil)

    if wibu.xor and wibu.brute:
        for i in range(256):
            print '{} => [+] Result => {}'.format(str(i), ''.join([chr(ord(l) ^ i) for l in wibu.str]))

    if wibu.xor and wibu.k:
        string = wibu.str
        n = wibu.k
        hasil = ''
        for c, k in zip(string, cycle(n)):
            hasil += chr(ord(c) ^ ord(k))
        fn_result(hasil)

    if wibu.md5:
        if wibu.md5 or wibu.e:
            fn_result(hashlib.md5(wibu.str.encode('utf')).hexdigest())

    if wibu.sha1:
        if wibu.sha1 or wibu.e:
            fn_result(hashlib.sha1(wibu.str.encode('utf')).hexdigest())

    if wibu.sha256:
        if wibu.sha256 or wibu.e:
            fn_result(hashlib.sha256(wibu.str.encode('utf')).hexdigest())

    if wibu.sha512:
        if wibu.sha512 or wibu.e:
            fn_result(hashlib.sha512(wibu.str.encode('utf')).hexdigest())