# Caesar's Cipher in Basic Python

**URL:** <https://forum.kirupa.com/t/caesars-cipher-in-basic-python/316724>\
**Category:** programming\
**Created:** [December 1, 2010, 4:31am UTC](https://forum.kirupa.com/t/caesars-cipher-in-basic-python/316724 "2010-12-01T04:31:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![boebarl1](https://avatars.discourse-cdn.com/v4/letter/b/3e96dc/32.png) [@boebarl1](https://forum.kirupa.com/u/boebarl1)\
**Post date:** [December 1, 2010, 4:31am UTC](https://forum.kirupa.com/t/caesars-cipher-in-basic-python/316724/1 "2010-12-01T04:31:12Z")

</div>

Hi,

I wrote this program to use the Caeser Cypher method to encode input from the user. I have figured out how to encode each Character, but I cant seem to concatenate the encoded Characters back together and return an encoded string on a single line? Here is where I am at so far, Any help would be greatly appreciated. Thanks in advance.

print (“Please tell me the password you want encrypted:”)  
message = input()  
length = len(message)  
index = 0  
index = int(index)  
while (index \< length):  
oneChar = message[index]  
ascNumber = ord(oneChar)   
ascNumber = ascNumber + 9  
if ascNumber \>= 122:  
ascNumber = ascNumber - 26  
ascChar = chr(ascNumber)  
print ("Your Encrypted Password is: ", ascChar)  
index = index + 1

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [May 25, 2024, 3:22am UTC](https://forum.kirupa.com/t/caesars-cipher-in-basic-python/316724/3 "2024-05-25T03:22:05Z")

</div>

I realize this question is over 13 years old, but I had to fiddle with this, and you were close!

```auto
print("Please tell me the password you want encrypted:")
message = input()
length = len(message)
index = 0
encoded_message = "" # Empty string to store the encoded message
while index < length:
    oneChar = message[index]
    ascNumber = ord(oneChar)
    ascNumber = ascNumber + 9
    if ascNumber >= 122:
        ascNumber = ascNumber - 26
    ascChar = chr(ascNumber)
    encoded_message += ascChar # This is the part that is missing
    message
    index = index + 1

print("Your Encrypted Password is:", encoded_message) # Print the entire encoded message on a single line

```

---

<div class="post-metadata">

**Author:** ![johni](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johni/32/26265_2.png) [@johni](https://forum.kirupa.com/u/johni)\
**Post date:** [May 25, 2024, 10:16pm UTC](https://forum.kirupa.com/t/caesars-cipher-in-basic-python/316724/4 "2024-05-25T22:16:18Z")

</div>

> [@boebarl1](#):
>
> Hi,
> 
> I wrote this program to use the Caeser Cypher method to encode input from the user. I have figured out how to encode each Character, but I cant seem to concatenate the encoded Characters back together and return an encoded string on a single line? Here is where I am at so far, Any help would be greatly appreciated. Thanks in advance.
> 
> print (“Please tell me the password you want encrypted:”)  
> message = input()  
> length = len(message)  
> index = 0  
> index = int(index)  
> while (index \< length):  
> oneChar = message[index]  
> ascNumber = ord(oneChar)  
> ascNumber = ascNumber + 9  
> if ascNumber \>= 122:  
> ascNumber = ascNumber - 26  
> ascChar = chr(ascNumber)  
> print ("Your Encrypted Password is: ", ascChar)  
> index = index + 1

To concatenate the encoded characters and return an encoded string on a single line, you need to accumulate the encoded characters in a variable, then print the entire accumulated string after the loop finishes. Here’s a corrected version of your program:

```auto
print("Please tell me the password you want encrypted:")
message = input()
length = len(message)
index = 0
encrypted_message = ""

while index < length:
    oneChar = message[index]
    ascNumber = ord(oneChar)
    ascNumber = ascNumber + 9
    if ascNumber >= 122:
        ascNumber = ascNumber - 26
    ascChar = chr(ascNumber)
    encrypted_message += ascChar # Concatenate the encoded character
    index += 1

print("Your Encrypted Password is:", encrypted_message)

```

**Explanation:**

1. **Initialization** : An empty string **encrypted\_message** is used to store the concatenated encoded characters.

2. **While Loop** : The loop iterates through each character in the input message.

3. **Character Encoding** : Each character is encoded using the Caesar Cipher method.

4. **Concatenation** : The encoded character **ascChar** is concatenated to **encrypted\_message** using **+=**.

5. **Print Result** : After the loop, the entire encrypted message is printed in one line.

**Example:**

If the input message is “hello”, the program will output an encrypted password according to the Caesar Cipher with a shift of 9.
