• Register
1 vote
28 views

Problem:

I am begginer in python programming language and I a very noob at it. I need a program which can can encode and decode caesar cipher in python.

Can anyone help me or provide me with some sample code.

 

Thanks in advance.

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

1 vote
 
Best answer

Answer:

I have got a sample code for your problem you can use it if you want .

def encrypt(texts,s): 
    result = "" 
  
    for i in range(len(texts)): 
        char = texts[i] 
  
        
        if (char.isupper()): 
            result += chr((ord(char) + s-65) % 26 + 65) 
  
        
        else: 
            result += chr((ord(char) + s - 97) % 26 + 97) 
  
    return result 
  
 
texts = "WALLSTREET"
s = 4
print ("Text  : " + texts) 
print ("Shift : " + str(s)) 
print ("Cipher: " + encrypt(texts,s)) 

Its Output is:

Text  : WALLSTREET
Shift : 4
Cipher: AEPPWXVIIX

To decrypt:

Cipher(n) = De-cipher(26-n)

Hope you may be able to understand the code if not fell free to ask me anything you want to know about this code.

Happy coding.

11 6 4
34,950 points

Related questions

0 votes
2 answers 298 views
298 views
Problem : I need to write a program that can encode and decode caesar cipher python.
asked Oct 21, 2019 peterlaw 6.9k points
0 votes
1 answer 101 views
101 views
Problem: how java provides a class Base64 to deal with encryption? You can encrypt and decrypt your data by using provided methods. You need to import java.util.Base64 in your source file to use its methods. how much class provides different encoders and decoders to encrypt information at each level.
asked Nov 6, 2020 Mashhoodch 13k points
0 votes
0 answers 2 views
2 views
Removes the numbers, special characters-Converts uppercase letters to lowercase letters, and vice versa
asked Mar 31 smita 120 points
1 vote
1 answer 190 views
190 views
Problem: I wrote a program that asks the user to enter the amount of a purchase and then it sums up the total bill with 15% vat and 0.07% service tax. I wrote the program in python: vat = 0.15 sales_tax = 0.075 product_price = float(input("Please enter the ... not defined I can not solve this thing. I am new in python programming language so please help me to solve this error. Thanks in advance.
asked May 6, 2020 samhaz 5k points
0 votes
1 answer 29 views
29 views
Problem: Write a Python program to get next day of a given date.Date is provided as day, month and year The input provided is always valid. Output should be day-month-year. Hint: print(day,"-",month,"-",year) will display day-month-yearAlso identify the test data and use it to test the program.
asked Jan 21 Mashhoodch 13k points
0 votes
1 answer 4 views
4 views
Problem: how to I Solve this: error: the local driver's license office has asked you to write a program that grades HELP! I need help understanding this: the local driver's license office has asked you to write a program that grades Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 11 Mashhoodch 13k points
1 vote
1 answer 894 views
894 views
Problem: I wrote a program in python that asks the user for a number n and prints the sum of the numbers 1 to n: x = 1, addition = 0 n = int(input('Please enter a number:')) for i in range(x, n): addition = addition + i print (addition) But when ... n): TypeError: 'tuple' object cannot be interpreted as an integer Is there any thing that is missing from my code. Please help me to solve this out.
asked Jun 10, 2020 samhaz 5k points
0 votes
1 answer 7 views
7 views
Problem: Can anyone help me about this given question? If anyone know about this then please answer me.
asked Mar 27 niyatiry 3.6k points
0 votes
1 answer 55 views
55 views
I'm stuck in below question plz explain it. Suppose u and v both denote sets in Python. Under what condition can we guarantee that u|v == u^v? I have tried by considering set values as 1,2,3 & 4,5,6.I'm getting answer as v should be subset of u.likewise what should be the correct condition
asked Oct 25, 2020 psandprop 2.4k points
0 votes
1 answer 31 views
31 views
Problem: any help : Write a program that squares an integer and prints the result..
asked Mar 6 Wafa Abu Yousef 6.1k points