Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change a character in a string automatically?

I am trying to make an encrypting program. So far, I have only been able to change the order. How can I make it change a character to another character ? Ex; 'n' => '&', 'a' => '*', etc

I have tried to make a variable array to change the character.

def convert():
    print('This will re-order your password')
    y = input('Your password? 13 letters, numbers & symbols:    ')
    l = y[0] + y[11] + y[10] + y[9] + y[8] + y[7] + y[6] + y[5] + y[4] + 
y[3] + y[2] + y[1] + y[12]
    print(l)


def original():
    print('This will re-order your password to its original state')
    z = input('Your muddled password? 13 letters, numbers & symbols:    ')
    t = z[0] + z[11] + z[10] + z[9] + z[8] + z[7] + z[6] + z[5] + z[4] + 
z[3] + z[2] + z[1] + z[12]
    print(t)


p = input('Convert or Convert to original? For \'Convert\', type \'c\' or 
\'C\' and for \'Convert to original\', type \'o\' or \'O\':    ')

if p == 'c' or 'C':
    convert()
elif p == 'o' or 'O':
    original()
else:
    print('Invalid')

#  Example Passwords:
#  6539HopPop
#  And@457654321
like image 468
Manan Avatar asked Dec 01 '25 13:12

Manan


1 Answers

Can't you just try replace method on string something like

password="Imback4u";
newpassword=password.replace(old char,new char)

For multiple replacing use

password.replace("value1", "").replace("value2", "text")
like image 50
Shubham Avatar answered Dec 04 '25 03:12

Shubham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!