A caesar cipher code This is code for a caesar cipher that I wrote, I would love for anyone who can to offer any improvements/corrections/more efficient methods they can think of. Thanks.
alphabet=[&quot;A&quot;,&quot;B&quot;,&quot;C&quot;,&quot;D&quot;,&quot;E&quot;,&quot;F&quot;,&quot;G&quot;,&quot;H&quot;,&quot;I&quot;,&quot;J&quot;,&quot;K&quot;,&quot;L&quot;,&quot;M&quot;,&quot;N&quot;,&quot;O&quot;,&quot;P&quot;,&quot;Q&quot;,&quot;R&quot;,&quot;S&quot;,&quot;T&quot;,&quot;U&quot;,&quot;V&quot;,&quot;W&quot;,&quot;X&quot;,&quot;Y&quot;,&quot;Z&quot;,&quot; &quot;,&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;0&quot;,&quot;,&quot;,&quot;.&quot;]
enc_text=[]
dec_text=[]

def number_check(a):
  valid=False
  while valid==False:
    try:
      number=int(a)
      valid=True
    except ValueError:
      print(&quot;Invalid entry, You must enter a number.&quot;)
      a=input(&quot;please enter a number.\n&quot;)
  return number

def encrypt():
  for x in org_text:
    index=alphabet.index(x)
    enc_letter=(index+int(enc_key))%39
    new_let=alphabet[enc_letter]
    enc_text.append(new_let)
  return enc_text

def decipher():
  for x in message:
    index=alphabet.index(x)
    dec_letter=(index-int(enc_key))%39
    new_let=alphabet[dec_letter]
    dec_text.append(new_let)
  return dec_text

enc_key=number_check(input(&quot;Please enter your encryption key:\n&quot;))
org_text=input(&quot;please enter the message you would like encrypted:\n&quot;).upper()
message=encrypt()
message1=&quot;&quot;.join(message)
print(message1)
decode=decipher()
decode1=&quot;&quot;.join(decode)
print(decode1)
PEP-8
White space!  Your code needs more white space!  The Style Guide for Python Code enumerates many coding conventions Python programs should follow.  One is binary operators (like =, ==, +, % should have one space character before and after the operator.
alphabet is a constant.  It never changes.  PEP-8 would recommend you changing the name to ALPHABET to indicate it is a constant.
List of characters
A string is essentially just a list of characters.  Moreover, it will behave exactly as if it is list of characters.
alphabet=[&quot;A&quot;,&quot;B&quot;,&quot;C&quot;,&quot;D&quot;,&quot;E&quot;,&quot;F&quot;,&quot;G&quot;,&quot;H&quot;,&quot;I&quot;,&quot;J&quot;,&quot;K&quot;,&quot;L&quot;,&quot;M&quot;,&quot;N&quot;,&quot;O&quot;,&quot;P&quot;,&quot;Q&quot;,&quot;R&quot;,&quot;S&quot;,&quot;T&quot;,&quot;U&quot;,&quot;V&quot;,&quot;W&quot;,&quot;X&quot;,&quot;Y&quot;,&quot;Z&quot;,&quot; &quot;,&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;0&quot;,&quot;,&quot;,&quot;.&quot;]

could be replaced with the much less verbose ...
alphabet = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890,.&quot;

... with no other changes required in your program.
One source of truth
How many characters are in your alphabet?  Did you count?  39?  Are you sure?  Great!  What if you added an apostrophe to the alphabet.  The 39 would become 40, and you'd have to change both occurrences of 39 in your code to 40.
Why are we counting and risking making a mistake?  Computers are much better at counting!
ALPHABET_LENGTH = len(alphabet)
...
    enc_letter = (index + int(enc_key)) % ALPHABET_LENGTH
...
    dec_letter = (index - int(enc_key)) % ALPHABET_LENGTH

Now if you decide additional letters should be included in the alphabet, you just add them; no other change would be required.
Global variables
alphabet is a global constant.  It never changes.  In contrast to that, enc_text, dec_text, org_text and message are global variables.  They are mutated by the program.
Avoid global variables.  They make the code harder to understand, and harder to maintain.
Consider encrypt().  You call it and org_text is processed, encrypted and added to the enc_text list.  What happens if you change org_text and call encrypt() again?  The new text gets added to enc_text.
Was that expected?
If enc_text was removed from global scope, and defined inside the encrypt() function, this unexpected behaviour would not happen.  Same with dec_text.
Additionally, global variables should not be used to pass the text to be encrypted/decrypted into the functions; these should be passed as parameters.
Bug
If you encrypt the message &quot;This fails!&quot;, the program crashes with the exception ValueError: '!' is not in list.
This is another reason to use an alphabet string instead of a list of characters: strings have another method, .find(), which will return -1 if the target isn't found.  A list has no such method, forcing you to use try: ... except: ... to catch the exception.