Last active
June 1, 2019 15:21
-
-
Save nenodias/aa7d314794521b34b4a8c9002ba43e6c to your computer and use it in GitHub Desktop.
Cifra.py
This file contains hidden or 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
import sys | |
ALPHABET = ' abcdefghijklmnopqrstuvwxyz' | |
ROOT = '3' | |
def decrypt(message): | |
m = '' | |
for c in message: | |
if c in ALPHABET: | |
c_index = ALPHABET.index(c) | |
m += ALPHABET[(c_index - ROOT) % len(ALPHABET)] | |
else: | |
m =+ c | |
return m | |
def encrypt(message): | |
m = '' | |
for c in message: | |
c_index = ALPHABET.index(c) | |
if __name__ == '__main__': | |
command = sys.argv[1].lower() | |
message = sys.argv[2].lower() | |
if command == 'encrypt': | |
print(encrypt(message)) | |
elif command == 'decrypt': | |
print(decrypt(message)) | |
else: | |
print(command + '--> command not found') |
This file contains hidden or 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
import hashlib | |
texto = 'Texto a ser criptografado' | |
txt_sha = hashlib.sha1(texto.encode()) | |
print(txt_sha.hexdigest()) |
This file contains hidden or 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
import sys | |
ALPHABET = ' abcdefghijklmnopqrstuvwxyz' | |
ROOT = '3' | |
def encrypt(message): | |
m = '' | |
for c in message: | |
if c in ALPHABET: | |
c_index = ALPHABET.index(c) | |
m += ALPHABET[(c_index + ROOT) % len(ALPHABET)] | |
else: | |
m =+ c | |
return m | |
def decrypt(message): | |
m = '' | |
for c in message: | |
if c in ALPHABET: | |
c_index = ALPHABET.index(c) | |
m += ALPHABET[(c_index - ROOT) % len(ALPHABET)] | |
else: | |
m =+ c | |
return m | |
def encrypt(message): | |
m = '' | |
for c in message: | |
c_index = ALPHABET.index(c) | |
if __name__ == '__main__': | |
command = sys.argv[1].lower() | |
message = sys.argv[2].lower() | |
if command == 'encrypt': | |
print(encrypt(message)) | |
elif command == 'decrypt': | |
print(decrypt(message)) | |
else: | |
print(command + '--> command not found') |
This file contains hidden or 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
import requests as r | |
import json | |
TOKEN = '' | |
# Executando requisição GET | |
resposta = r.get("https://api.codenation.dev/v1/challenge/dev-ps/generate-data?token="+TOKEN) | |
with open('answer.json', 'w') as arquivo:# Abrindo/Criando o arquivo para escrita (w) | |
retorno_json = resposta.json() # Pegando objeto JSON convertido em mapa | |
retorno_text = resposta.text # Pegando o texto | |
arquivo.write(retorno_text) # Escrevendo o arquivo | |
print(retorno_json) |
This file contains hidden or 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
ARQUIVO = 'answer.json' | |
multipart_form_data = { | |
'answer': (ARQUIVO, open(ARQUIVO, 'rb')), | |
} | |
resp = r.post(URL_POST+TOKEN, files=multipart_form_data) | |
print(resp.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment