josharsh / 100LinesOfCode

Let's build something productive in less than 100 Lines of Code.
GNU General Public License v3.0
648 stars 310 forks source link

Add Program: Simple Caesar Cipher En-/Decoder #365

Open KnochenMarkSaege opened 8 months ago

KnochenMarkSaege commented 8 months ago

As requested in the CONTRIBUTING.md, I'm opening this issue to request a merge for my pull request for my branch "Simple Caesar Cipher En-/Decoder"

I created a little C++ program which encodes & decodes input text by a shit-modifier. I also included a README.md file that explains how to works.

This Issue is regarding Pull Request #366 .

K0MPLEXWorksTogether commented 6 months ago

Can I take this up. I already have written some code for this. Check it out: https://replit.com/@AbhiramMangipud/Caeser-Cipher Btw, there are more program's available on my Replit. Ping me if you need anything, or else, use anything you want. Here's a small preview of my code:


import art
# Printing The Cool ASCII Art.
print(art.logo)

# Maintain A List Of ALl The English Alphabet.
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

def caesar(start_text, shift_amount, cipher_direction):
    # Maintaining End Text.
    end_text = ""

    # Check For Direction Of Cipher.
    if direction == "encode":
      pass
    elif direction == "decode":
      shift_amount *= -1
    else:
      print("You have entered an invalid ciphering direction. Try again.")
      return None

    # Adding Elements To The Cipher Text.
    for letter in start_text:
      if letter in alphabet:
        position = alphabet.index(letter)
        new_position = (position + shift_amount) % 26
        end_text += alphabet[new_position]
      else:
        end_text += letter
    # Displaying Cipher Text.
    print(f"The {cipher_direction}d text is: {end_text}")

# Game Loop.
goAgain = True
while(goAgain):
  direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
  text = input("Type your message:\n").lower()
  shift = int(input("Type the shift number:\n"))

  caesar(start_text=text, shift_amount=shift, cipher_direction=direction)

  another_try = input("Enter 'go' if you want to go again. Else enter 'stop'.\n")
  if another_try == 'go':
    pass
  elif another_try == 'stop':
    print("Goodbye Then!")
    goAgain = False
  else:
    print("You have entered invalid choice. Stopping...")
    goAgain = False
KnochenMarkSaege commented 6 months ago

@K0MPLEXWorksTogether not 100% sure if I'm interpreting your message correctly, but if you're asking me, if you can use my code for the caesar's cipher: sure, go ahead. The second I contributed it to this repo I considered it Open Source, so it's available to be used for everyone who finds it :)

K0MPLEXWorksTogether commented 6 months ago

I'm so sorry. I didn't know about you opening this issue, to get an approval for your pull request. I thought the issue was up for taking.

KnochenMarkSaege commented 6 months ago

I think the owner of the repo isn't actively maintaining it anymore. But you can still feel free to use my code, if you want to, np for me :)