2

So currently I am working on a Caesar cypher app, my code looks like this (coded by RAD software https://anvil.works/)

The problem is that I don't get any output when I try to run the program and I think that it could be self.text_area_2 = cipher_encrypt(plain_text, key). I'm not sure if I'm using the correct statement to display the output correctly.

What statement should I use instead? Am I doing the right thing?


from ._anvil_designer import Form2Template
from anvil import *

class Form2(Form2Template):
  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)


  def button_1_click(self, **event_args): 

    def cipher_encrypt(plain_text, key):

      plain_text = self.text_area_1.text
      key = self.text_box_1.text

      encrypted = ""

      for c in plain_text:

        if c.isupper(): #check if it's an uppercase character

            c_index = ord(c) - ord('A')

            # shift the current character by key positions
            c_shifted = (c_index + key) % 26 + ord('A')

            c_new = chr(c_shifted)

            encrypted += c_new

        elif c.islower(): #check if its a lowecase character

            # subtract the unicode of 'a' to get index in [0-25) range
            c_index = ord(c) - ord('a') 

            c_shifted = (c_index + key) % 26 + ord('a')

            c_new = chr(c_shifted)

            encrypted += c_new

        elif c.isdigit():

            # if it's a number,shift its actual value 
            c_new = (int(c) + key) % 10

            encrypted += str(c_new)

        else:

            # if its neither alphabetical nor a number, just leave it like that
            encrypted += c

      return encrypted



    self.text_area_2 = cipher_encrypt(plain_text, key)
drum
  • 5,416
  • 7
  • 57
  • 91

0 Answers0