Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7526137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:45:18+00:00 2026-05-30T03:45:18+00:00

So I wrote a little script in python that brings up a gui with

  • 0

So I wrote a little script in python that brings up a gui with 2 buttons and a text field. you type into the text area and click encrypt and the text all of a sudden looks crazy. coooooool.

but then when you hit decrypt, it doesn’t go back to the original. here is the code

from Tkinter import *
import ttk

root = Tk()
textArea = Text(root, state = "normal")

def encrypt():
    message = textArea.get('1.0', 'end')
    newMessage = ''
    lastChar = ''

    for c in message:
        if lastChar != '':
            newMessage += chr((ord(c) + ord(lastChar)) % 256)
            lastChar = chr((ord(c) + ord(lastChar)) % 256)
        else:
            newMessage += chr((ord(c) + 5) % 256)
            lastChar = chr((ord(c) + 5) % 256)

    textArea.delete('1.0', 'end')
    textArea.insert('end', newMessage)

def decrypt():
    message = textArea.get('1.0', 'end')
    newMessage = ''
    lastChar = ''

    for c in message:
        if lastChar != '':
            newMessage += chr((ord(c) - ord(lastChar)) % 256)
            lastChar = chr((ord(c) - ord(lastChar)) % 256)
        else:
            newMessage += chr((ord(c) - 5) % 256)
            lastChar = chr((ord(c) - 5) % 256)

    textArea.delete('1.0', 'end')
    textArea.insert('end', newMessage)

encrypt = ttk.Button(root, text = "Encrypt", command = encrypt)

encrypt.pack({"side": "top"})

decrypt = ttk.Button(root, text = "Decrypt", command = decrypt)

decrypt.pack({"side": "top"})

textArea.pack({"side": "bottom"});

mainloop()

the problem is that it doesn’t show the original text. It just seems to make it more cryptic. what is wrong here? Please help.

update:
a changed it so it just adds 5. and It works. So that tells me that it’s the part where I add last characters code value. There is still one problem: it adds a new line and this strange line character (not the pipe —> |).

now the code is fixed. thanks. here is the result:
WW1ueCVueCV1d2p5eX4laHR0cTMlWW1mc3AlfnR6JXh5ZmhwJXR7andrcXR8JWt0dyV5bWolZnN4fGp3Mw8=

after I made the decrypt so It doesn’t take away five, it worked. Thanks again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:45:21+00:00Added an answer on May 30, 2026 at 3:45 am

    You can’t put arbitrary bytes into a text area.

    Your encryption algorithm is purely bytewise – it works on the numeric values of the characters. This isn’t going to work, even for ASCII, because byte 0 is an ASCII NUL – treated specially, and byte 127 (what ‘Z’, character 122, becomes when shifted up by five) is a DEL character: not what you want! Moving beyond ASCII, the real world’s UTF-8 has thousands of invalid byte sequences.

    If you’re going to be using bytewise encryption like this, you can’t put the results into a text field – it’s binary data. If you want it to be able to go into a text field, you must make sure it’s valid text without control characters, NUL bytes, or invalid byte sequences.

    One easy way of making the binary sanitary is to Base64-encode it on encryption, and have the first step of decryption be Base64 decoding.

    Final note: you’re also encrypting the newline at the end of the text area. Probably not something you wish to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings. I have written a little python script that calls MySQL in a subprocess.
I wrote a little Python script wrapcl.py script which wraps our compiler binary (
I wrote a little python script to accept BitBucket POST callbacks of repository changes
I have a little python script that pulls emails from a POP mail address
I wrote a little drawing script (canvas) for this website: http://scri.ch/ When you click
I have a little script I wrote in python and it actually works on
I wrote a python script that rotates an image 90 degrees. I am including
I am still learning Python and as a little Project I wrote a script
I wrote a little search script for a client, it works and words get
I'm trying to write a little Emacs Lisp script that reads a csv file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.