Sorry for the messy code. I didn't have time really. I'm new and just been experimenting. I just wanna know why the strings aren't replaced. As you can see, the "b64ed" and "final_product" are the same...

Sorry in advance. I'm stupid xD

import base64;
import time;
import os;
import random;
import string;
import Crypto
from Crypto.PublicKey import RSA
from Crypto import Random
import ast


enc_method = input("Would you like to manually input the text or load a .txt file? \n Press 1 for manual or 2 for importing: \n");


if enc_method == "1":
    filename = input("Enter the filename.txt: ");
    print("Importing String.... \n")
    with open(filename) as fn:
        toEnc_string = fn.read();
    print("String imported!");
    print(toEnc_string)

elif enc_method == "2":
    toEnc_string = input("Paste or Type the string you want to encrypt: \n");

else:
    print("For fucks sake...")


def oneS():
    return time.sleep(1)


def clearScreen():
    print("Clearing screen in 5...")
    time.sleep(1)
    print("4...")
    time.sleep(1)
    print("3...")
    time.sleep(1)
    print("2...")
    time.sleep(1)
    os.system("clear")

clearScreen()

def randomString(lenOfThatshit):
    letters = string.ascii_letters
    return ''.join(random.choice(letters) for i in range(lenOfThatshit))

def bs64e(x):
    rummed = x.encode("utf-8")
    encoded = base64.b64encode(rummed)
    return encoded

print("You will now be asked to chose random Characters about 10 times. Choose differently each time.")
rs1 = input("Choose 6 random letters without spaces. Dont repeat: ")
rs2 = randomString(len(rs1))
#rs2 = input("Choose 6 more random letter without spaces. Dont repeat: ")

randStr = list(rs1)
randStr2 = list(rs2)

b64ed = str(bs64e(toEnc_string))

for i in range(6):
    final_product = b64ed.replace(str(randStr[i]) , str(randStr2[i]))
    print(str(randStr[i]) + "to " + str(randStr2[i]))

passes = open("the special random characters.txt", "w")
amount_written = passes.write(str(randStr) + "\n" + str(randStr2))

print(b64ed)
print("\n")
print(len(b64ed))
print("\n")
print(final_product)
print("\n")
print(len(final_product))
#print("Number of bytes written : " + str(amount_written))

passes.close()

Again, the code is really messy, I know. And there are many imports unused still. Forgive me. Also I will take any ideas.

1 Answers

0
ruohola On Best Solutions

You had a logical error there, always replacing chars in the b64ed string, so only the last of the replacement characters could actually be replaced. So you would see changes only if b64ed happened to contain the randStr[5] character, otherwise final_product would just be the exact same as b64ed.

Part of your code should look like this:

final_product = b64ed
for i in range(6):
    final_product = final_product.replace(str(randStr[i]) , str(randStr2[i]))
    print(str(randStr[i]) + " to " + str(randStr2[i]))