3
Contributors
2
Replies
6
Views
5 Years
Discussion Span
Last Post by ZZucker
0

Something like this will do:

def hide_word(word):
    """hide word as whitespace like tabs"""
    temps = ""
    tab = '\t'
    new_line = '\n'
    for letter in word:
        # 'A' would be 1 tab, 'B' 2 tabs etc.
        temps += tab * (ord(letter) - 64) + new_line
    return temps


text = "My name is "
hide = "Bob"

new_text = text + hide_word(hide)


# test
print('-'*60)
print(new_text)
print('-'*60)
# unhide
nt = 0
temps = ""
for c in new_text:
    if c == '\t':
        #print('|')
        nt += 1
    elif c == '\n':
        temps += chr(nt + 64)
        nt = 0
    else:
        temps += c
        nt = 0

print(temps)

Edited by ZZucker

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.