encryption - Conditional swap of string characters in python? (Dynamic Substitution Cipher) -
i finished small viginere cipher code, , thinking of trying make dynamic, adding swap of 2 characters in sbox after each character encrypted.
the problem is, everywhere i've seen has info on swapping characters in string, positions of characters swapped have written out in code itself. there way make characters swapped dependent on outcome of round of function?
some clarification: @ top of code have:
a = 'abcdefghijklmnopqrstuvwxyz'
then in encrypt function have:
for p,k in zip(plaintext,keystream): pt = a.index(p) kt = a.index(k) c = pt + kt if c > 25: c -= 25 c = a[c] ciphertext += c
so question is, if wanted swap 2 characters around in a
after each character in plaintext encrypted, , have characters swapped dependent on values of a.index(p)
, a.index(k)
each character being encrypted? how 1 go doing that?
something work:
if not p == k: x, y = p, k if p < k else k, p = a[:x] + a[y] + a[x+1:y] + a[x] + a[y+1:]
this takes till first char, uses other char in place, between 2 chars, replaces second char first, , after second char
Comments
Post a Comment