Created
April 4, 2019 22:28
-
-
Save kardoso/e1157997f9dd7ae0ce3e1a9b4dc39dea to your computer and use it in GitHub Desktop.
Código feito para o desafio 'Criptografia de Júlio César' do Codenation. Este código descriptografa uma mensagem com base na cifra de César.
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/python3 | |
import json | |
import hashlib | |
import requests | |
access_token = 'CODENATION_TOKEN' | |
def get_hash(phrase): | |
return hashlib.sha1(phrase.encode()).hexdigest() | |
def get_data(): | |
url = ('https://api.codenation.dev/v1/challenge/dev-ps/generate-data?token=%s' | |
% access_token) | |
r = requests.get(url) | |
return r.json() | |
def send_data(data): | |
url = ('https://api.codenation.dev/v1/challenge/dev-ps/submit-solution?token=%s' | |
% access_token) | |
files = {'answer': json.dumps(data).encode('utf-8')} | |
r = requests.post(url, files=files) | |
print(r.json()) | |
print(r.status_code) | |
def decrypt(phrase, places): | |
alphabet = [chr(i) for i in range(ord('a'),ord('z')+1)] | |
decrypted = "" | |
for char in phrase: | |
if char in alphabet: | |
char = alphabet[alphabet.index(char)-places] | |
decrypted += char | |
return decrypted | |
def main(): | |
data = get_data() | |
encrypted_phrase = data['cifrado'] | |
places = data['numero_casas'] | |
decrypted_phrase = decrypt(encrypted_phrase, places) | |
data['decifrado'] = decrypted_phrase | |
data['resumo_criptografico'] = get_hash(decrypted_phrase) | |
send_data(data) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment