Prepare to release HOP 1.0.2
This commit is contained in:
parent
9107971194
commit
77a1357e4f
|
@ -1,153 +1,160 @@
|
||||||
#Changelog:
|
#Changelog:
|
||||||
#HOP Encode
|
#HOP Encode
|
||||||
#1.0:
|
#1.0:
|
||||||
#Released HOP Encode
|
#Released HOP Encode
|
||||||
#1.0.1:
|
#1.0.1:
|
||||||
#Updated version number
|
#Updated version number
|
||||||
#Added optimize for Discord option
|
#Added optimize for Discord option
|
||||||
#Added changelog
|
#Added changelog
|
||||||
#Hop Decode
|
#HOP Decode
|
||||||
#1.0:
|
#1.0:
|
||||||
#Released HOP decode
|
#Released HOP decode
|
||||||
#1.0.1:
|
#1.0.1:
|
||||||
#Updated version number to match that of HOP Encode
|
#Updated version number to match that of HOP Encode
|
||||||
#Added changelog
|
#Added changelog
|
||||||
|
#HOP
|
||||||
import base64
|
#1.0.2:
|
||||||
def decode(ciphertext, key):
|
#Combined HOP Encode and HOP Decode
|
||||||
steponel = list(ciphertext)
|
#Integrated GitHub and repl.it
|
||||||
stepone = ""
|
#Added several files, including .replit, CODE_OF_CONDUCT.md, CONTRIBUTING.md, README.md, and SECURITY.md
|
||||||
for i in range(len(steponel)-1):
|
#Moved input, print, and import statements outside functions
|
||||||
stepone=stepone+steponel[i]
|
#Added ability to choose on runtime encode or decode
|
||||||
steptwo = stepone.encode('utf-8')
|
|
||||||
steptwob = base64.a85decode(steptwo)
|
import base64
|
||||||
steptwoc = steptwob.decode('utf-8')
|
def decode(ciphertext, key):
|
||||||
def vigenere_dec(cipher,key):
|
steponel = list(ciphertext)
|
||||||
alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
|
stepone = ""
|
||||||
input_string = ""
|
for i in range(len(steponel)-1):
|
||||||
dec_key = ""
|
stepone=stepone+steponel[i]
|
||||||
dec_string = ""
|
steptwo = stepone.encode('utf-8')
|
||||||
dec_key = key
|
steptwob = base64.a85decode(steptwo)
|
||||||
dec_key = dec_key.lower()
|
steptwoc = steptwob.decode('utf-8')
|
||||||
input_string = cipher
|
def vigenere_dec(cipher,key):
|
||||||
input_string = input_string.lower()
|
alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
string_length = len(input_string)
|
input_string = ""
|
||||||
expanded_key = dec_key
|
dec_key = ""
|
||||||
expanded_key_length = len(expanded_key)
|
dec_string = ""
|
||||||
while expanded_key_length < string_length:
|
dec_key = key
|
||||||
expanded_key = expanded_key + dec_key
|
dec_key = dec_key.lower()
|
||||||
expanded_key_length = len(expanded_key)
|
input_string = cipher
|
||||||
key_position = 0
|
input_string = input_string.lower()
|
||||||
for letter in input_string:
|
string_length = len(input_string)
|
||||||
if letter in alphabet:
|
expanded_key = dec_key
|
||||||
position = alphabet.find(letter)
|
expanded_key_length = len(expanded_key)
|
||||||
key_character = expanded_key[key_position]
|
while expanded_key_length < string_length:
|
||||||
key_character_position = alphabet.find(key_character)
|
expanded_key = expanded_key + dec_key
|
||||||
key_position = key_position + 1
|
expanded_key_length = len(expanded_key)
|
||||||
new_position = position - key_character_position
|
key_position = 0
|
||||||
if new_position > 35:
|
for letter in input_string:
|
||||||
new_position = new_position + 36
|
if letter in alphabet:
|
||||||
new_character = alphabet[new_position]
|
position = alphabet.find(letter)
|
||||||
dec_string = dec_string + new_character
|
key_character = expanded_key[key_position]
|
||||||
else:
|
key_character_position = alphabet.find(key_character)
|
||||||
dec_string = dec_string + letter
|
key_position = key_position + 1
|
||||||
return(dec_string)
|
new_position = position - key_character_position
|
||||||
def stepfour(stepthree):
|
if new_position > 35:
|
||||||
stepthree=str(int(stepthree,36))
|
new_position = new_position + 36
|
||||||
test = list(stepthree)
|
new_character = alphabet[new_position]
|
||||||
if len(test)%3==1:
|
dec_string = dec_string + new_character
|
||||||
stepthree="00"+stepthree
|
else:
|
||||||
if len(test)%3==2:
|
dec_string = dec_string + letter
|
||||||
stepthree="0"+stepthree
|
return(dec_string)
|
||||||
stepthreel = list(stepthree)
|
def stepfour(stepthree):
|
||||||
stepfourl = [""]*int((float(len(stepthreel))/3))
|
stepthree=str(int(stepthree,36))
|
||||||
k = 0
|
test = list(stepthree)
|
||||||
while k < len(stepthreel)-2:
|
if len(test)%3==1:
|
||||||
stepfourl[int(k/3)] = stepthreel[k] + stepthreel[k+1] + stepthreel[k+2]
|
stepthree="00"+stepthree
|
||||||
k = k + 3
|
if len(test)%3==2:
|
||||||
for j in range(len(stepfourl)):
|
stepthree="0"+stepthree
|
||||||
temp = stepfourl[j]
|
stepthreel = list(stepthree)
|
||||||
temp = int(temp)
|
stepfourl = [""]*int((float(len(stepthreel))/3))
|
||||||
temp = chr(temp)
|
k = 0
|
||||||
stepfourl[j] = temp
|
while k < len(stepthreel)-2:
|
||||||
stepfour=""
|
stepfourl[int(k/3)] = stepthreel[k] + stepthreel[k+1] + stepthreel[k+2]
|
||||||
for l in range(len(stepfourl)):
|
k = k + 3
|
||||||
stepfour = stepfour + stepfourl[l]
|
for j in range(len(stepfourl)):
|
||||||
return(stepfour)
|
temp = stepfourl[j]
|
||||||
stepthree = vigenere_dec(steptwoc, key)
|
temp = int(temp)
|
||||||
stepfour = stepfour(stepthree)
|
temp = chr(temp)
|
||||||
output = "Your decoded message: "+stepfour
|
stepfourl[j] = temp
|
||||||
return output;
|
stepfour=""
|
||||||
def encode(plaintext, key):
|
for l in range(len(stepfourl)):
|
||||||
def b36_encode(i):
|
stepfour = stepfour + stepfourl[l]
|
||||||
if i < 0: return "-" + b36_encode(-i)
|
return(stepfour)
|
||||||
if i < 36: return "0123456789abcdefghijklmnopqrstuvwxyz"[i]
|
stepthree = vigenere_dec(steptwoc, key)
|
||||||
return b36_encode(i // 36) + b36_encode(i % 36)
|
stepfour = stepfour(stepthree)
|
||||||
def stepone(plaintext):
|
output = "Your decoded message: "+stepfour
|
||||||
magicasciipowers = list(plaintext)
|
return output;
|
||||||
numbersgohere = [""]*len(magicasciipowers)
|
def encode(plaintext, key):
|
||||||
for i in range(len(magicasciipowers)):
|
def b36_encode(i):
|
||||||
temp = magicasciipowers[i]
|
if i < 0: return "-" + b36_encode(-i)
|
||||||
temp = ord(temp)
|
if i < 36: return "0123456789abcdefghijklmnopqrstuvwxyz"[i]
|
||||||
if (temp<100):
|
return b36_encode(i // 36) + b36_encode(i % 36)
|
||||||
numbersgohere[i]="0"+str(temp)
|
def stepone(plaintext):
|
||||||
else:
|
magicasciipowers = list(plaintext)
|
||||||
numbersgohere[i]=str(temp)
|
numbersgohere = [""]*len(magicasciipowers)
|
||||||
numbers = ""
|
for i in range(len(magicasciipowers)):
|
||||||
for i in range(len(numbersgohere)):
|
temp = magicasciipowers[i]
|
||||||
numbers=numbers+numbersgohere[i]
|
temp = ord(temp)
|
||||||
return(int(numbers))
|
if (temp<100):
|
||||||
def vigenere_enc(stepone,key):
|
numbersgohere[i]="0"+str(temp)
|
||||||
alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
|
else:
|
||||||
input_string = ""
|
numbersgohere[i]=str(temp)
|
||||||
enc_key = ""
|
numbers = ""
|
||||||
enc_string = ""
|
for i in range(len(numbersgohere)):
|
||||||
enc_key = key
|
numbers=numbers+numbersgohere[i]
|
||||||
enc_key = enc_key.lower()
|
return(int(numbers))
|
||||||
input_string = stepone
|
def vigenere_enc(stepone,key):
|
||||||
input_string = input_string.lower()
|
alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
string_length = len(input_string)
|
input_string = ""
|
||||||
expanded_key = enc_key
|
enc_key = ""
|
||||||
expanded_key_length = len(expanded_key)
|
enc_string = ""
|
||||||
while expanded_key_length < string_length:
|
enc_key = key
|
||||||
expanded_key = expanded_key + enc_key
|
enc_key = enc_key.lower()
|
||||||
expanded_key_length = len(expanded_key)
|
input_string = stepone
|
||||||
key_position = 0
|
input_string = input_string.lower()
|
||||||
for letter in input_string:
|
string_length = len(input_string)
|
||||||
if letter in alphabet:
|
expanded_key = enc_key
|
||||||
position = alphabet.find(letter)
|
expanded_key_length = len(expanded_key)
|
||||||
key_character = expanded_key[key_position]
|
while expanded_key_length < string_length:
|
||||||
key_character_position = alphabet.find(key_character)
|
expanded_key = expanded_key + enc_key
|
||||||
key_position = key_position + 1
|
expanded_key_length = len(expanded_key)
|
||||||
new_position = position + key_character_position
|
key_position = 0
|
||||||
if new_position > 35:
|
for letter in input_string:
|
||||||
new_position = new_position - 36
|
if letter in alphabet:
|
||||||
new_character = alphabet[new_position]
|
position = alphabet.find(letter)
|
||||||
enc_string = enc_string + new_character
|
key_character = expanded_key[key_position]
|
||||||
else:
|
key_character_position = alphabet.find(key_character)
|
||||||
enc_string = enc_string + letter
|
key_position = key_position + 1
|
||||||
return(enc_string)
|
new_position = position + key_character_position
|
||||||
steptwo = vigenere_enc(b36_encode(stepone(plaintext)),key)
|
if new_position > 35:
|
||||||
steptwob = steptwo.encode('utf-8')
|
new_position = new_position - 36
|
||||||
stepthree = base64.a85encode(steptwob)
|
new_character = alphabet[new_position]
|
||||||
stepthreeb = stepthree.decode('utf-8')
|
enc_string = enc_string + new_character
|
||||||
stepfour = str(stepthreeb)+"h"
|
else:
|
||||||
answer = False
|
enc_string = enc_string + letter
|
||||||
while answer == False:
|
return(enc_string)
|
||||||
discord = input("Optimize for discord? y or n: ")
|
steptwo = vigenere_enc(b36_encode(stepone(plaintext)),key)
|
||||||
if(discord=="y"):
|
steptwob = steptwo.encode('utf-8')
|
||||||
answer = True
|
stepthree = base64.a85encode(steptwob)
|
||||||
stepfour = "```"+str(stepthreeb)+"h```"
|
stepthreeb = stepthree.decode('utf-8')
|
||||||
elif(discord=="n"):
|
stepfour = str(stepthreeb)+"h"
|
||||||
answer = True
|
answer = False
|
||||||
output="Your encoded message: "+stepfour
|
while answer == False:
|
||||||
return output
|
discord = input("Optimize for discord? y or n: ")
|
||||||
var = input("Encode or Decode? 1 for encode, 2 for decode: ")
|
if(discord=="y"):
|
||||||
if (var=="1"):
|
answer = True
|
||||||
ciphertext = input("Enter message to encode: ")
|
stepfour = "```"+str(stepthreeb)+"h```"
|
||||||
key = input("Enter encryption key: ")
|
elif(discord=="n"):
|
||||||
print(encode(ciphertext, key))
|
answer = True
|
||||||
elif (var=="2"):
|
output="Your encoded message: "+stepfour
|
||||||
plaintext = input("Enter message to decode: ")
|
return output
|
||||||
key = input("Enter encryption key: ")
|
var = input("Encode or Decode? 1 for encode, 2 for decode: ")
|
||||||
print(decode(plaintext, key))
|
if (var=="1"):
|
||||||
|
ciphertext = input("Enter message to encode: ")
|
||||||
|
key = input("Enter encryption key: ")
|
||||||
|
print(encode(ciphertext, key))
|
||||||
|
elif (var=="2"):
|
||||||
|
plaintext = input("Enter message to decode: ")
|
||||||
|
key = input("Enter encryption key: ")
|
||||||
|
print(decode(plaintext, key))
|
Loading…
Reference in New Issue