[Tutorial] Creating a simple encryption code with python 3.6

in #utopian-io6 years ago (edited)

images.png
Image source
WHAT YOU WOULD LEARN?

CONTENTS
"""if ord('a') == 97:
print ("true")
else:
print("not true")"""#forget about this line i was just testing something
encrypted = []

sentence = input("Enter characters to encrypt or decrypt")#this is where the user enters the sentence or word to be encrypted
for p in sentence: #this line selects the characters in the entered sentence or word one by one, represents them with "p"
#(that is, if it selects "i" it sorta stores it in the variable "p")

and performs the following code on them.

if ord(p) == 51: #the ord(p). now remember i told you that what ord does is find the ascii code of a character that has been put in 
#the bracket so what this line does is it finds the ascii code that was stored in p and checks if it's ascii code is equal to 51
#if it is true it adds 15 to the ascii number of the character. So, assuming y was the character stored in p if the ascii code of y
#is 51 it will now add 15 to 51 to give you 66 right.
    p = ord(p) + 15#this is the line that adds 15 to the ascii code if it is equal to 51 when it adds it, it stores the sum in p
    encrypted.append(chr(p))#now remember that is told you that char() finds the character whose ascii code is the number entered in
    #its bracket. So, what char p does is that it checks for which character has the ascii code of the number stored in p.
    #the "encrypted" in the line is the name of an array. An array is like a cabinet that stores characters and strings and numbers.
    #now, what that line "encrypted.append(chr(p))" does is it finds the character whose ascii code is the number stored in p and then
    #stores the character in that array.
    
    #so take for instance that "y" was the selected character at the beginning and its ascii code is 51, it adds 15 to 51 to give 66
    #lets now say for instance that the character whose ascii code is "66" is "t" it then add "t" to the array.
    
    
elif ord(p) == 66:
    p = ord(p) - 15
    encrypted.append(chr(p))

elif ord(p) == 42:
    p = ord(p) + 29
    encrypted.append(chr(p))

elif ord(p) == 71:
    p = ord(p) - 29
    encrypted.append(chr(p))

elif ord(p) == 48:
    p = ord(p) + 7
    encrypted.append(chr(p))

elif ord(p) == 55:
    p = ord(p) - 7
    encrypted.append(chr(p))

elif ord(p) == 37:
    p = ord(p) + 26
    encrypted.append(chr(p))

elif ord(p) == 63:
    p = ord(p) - 26
    encrypted.append(chr(p))

elif ord(p) == 45:
    p = ord(p) + 15
    encrypted.append(chr(p))

elif ord(p) == 60:
    p = ord(p) - 15
    encrypted.append(chr(p))

elif ord(p) == 35:
    p = ord(p) + 29
    encrypted.append(chr(p))

elif ord(p) == 64:
    p = ord(p) - 29
    encrypted.append(chr(p))

elif ord(p) == 66:
    p = ord(p) - 15
    encrypted.append(chr(p))

elif ord(p) == 32:
    p = ord(p) + 25
    encrypted.append(chr(p))

elif ord(p) == 57:
    p = ord(p) - 25
    encrypted.append(chr(p))

elif ord(p) == 38:
    p = ord(p) + 27
    encrypted.append(chr(p))

elif ord(p) == 65:
    p = ord(p) - 27
    encrypted.append(chr(p))

elif ord(p) == 49:
    p = ord(p) + 21
    encrypted.append(chr(p))

elif ord(p) == 70:
    p = ord(p) - 21
    encrypted.append(chr(p))

elif ord(p) == 47:
    p = ord(p) + 9
    encrypted.append(chr(p))

elif ord(p) == 56:
    p = ord(p) - 9
    encrypted.append(chr(p))

elif ord(p) == 44:
    p = ord(p) + 8
    encrypted.append(chr(p))

elif ord(p) == 52:
    p = ord(p) - 8
    encrypted.append(chr(p))

elif ord(p) == 36:
    p = ord(p) + 31
    encrypted.append(chr(p))

elif ord(p) == 67:
    p = ord(p) - 31
    encrypted.append(chr(p))

elif ord(p) == 43:
    p = ord(p) + 25
    encrypted.append(chr(p))

elif ord(p) == 68:
    p = ord(p) - 25
    encrypted.append(chr(p))

elif ord(p) == 39:
    p = ord(p) + 22
    encrypted.append(chr(p))

elif ord(p) == 59:
    p = ord(p) + 10
    encrypted.append(chr(p))

elif ord(p) == 69:
    p = ord(p) - 10
    encrypted.append(chr(p))

elif ord(p) == 33:
    p = ord(p) + 20
    encrypted.append(chr(p))

elif ord(p) == 53:
    p = ord(p) - 20
    encrypted.append(chr(p))

elif ord(p) == 34:
    p = ord(p) + 20
    encrypted.append(chr(p))

elif ord(p) == 54:
    p = ord(p) - 20
    encrypted.append(chr(p))

elif ord(p) == 58:
    p = ord(p) + 4
    encrypted.append(chr(p))

elif ord(p) == 62:
    p = ord(p) - 4
    encrypted.append(chr(p))

elif ord(p) == 40:
    p = ord(p) + 24
    encrypted.append(chr(p))

elif ord(p) == 46:
    p = ord(p) - 24
    encrypted.append(chr(p))

elif ord(p) == 41:
    p = ord(p) + 9
    encrypted.append(chr(p))

elif ord(p) == 50:
    p = ord(p) - 9
    encrypted.append(chr(p))

elif ord(p) == 72:
    p = ord(p) + 31
    encrypted.append(chr(p))

elif ord(p) == 103:
    p = ord(p) - 31
    encrypted.append(chr(p))

elif ord(p) == 82:
    p = ord(p) + 27
    encrypted.append(chr(p))

elif ord(p) == 109:
    p = ord(p) - 27
    encrypted.append(chr(p))

elif ord(p) == 87:
    p = ord(p) + 11
    encrypted.append(chr(p))

elif ord(p) == 98:
    p = ord(p) - 11
    encrypted.append(chr(p))

elif ord(p) == 79:
    p = ord(p) + 26
    encrypted.append(chr(p))

elif ord(p) == 105:
    p = ord(p) - 26
    encrypted.append(chr(p))

elif ord(p) == 84:
    p = ord(p) + 27
    encrypted.append(chr(p))

elif ord(p) == 111:
    p = ord(p) - 27
    encrypted.append(chr(p))

elif ord(p) == 75:
    p = ord(p) + 25
    encrypted.append(chr(p))

elif ord(p) == 100:
    p = ord(p) - 25
    encrypted.append(chr(p))

elif ord(p) == 81:
    p = ord(p) + 23
    encrypted.append(chr(p))

elif ord(p) == 104:
    p = ord(p) - 23
    encrypted.append(chr(p))

elif ord(p) == 86:
    p = ord(p) + 21
    encrypted.append(chr(p))

elif ord(p) == 107:
    p = ord(p) - 21
    encrypted.append(chr(p))

elif ord(p) == 83:
    p = ord(p) + 12
    encrypted.append(chr(p))

elif ord(p) == 95:
    p = ord(p) - 12
    encrypted.append(chr(p))

elif ord(p) == 78:
    p = ord(p) + 16
    encrypted.append(chr(p))

elif ord(p) == 94:
    p = ord(p) - 16
    encrypted.append(chr(p))

elif ord(p) == 85:
    p = ord(p) + 12
    encrypted.append(chr(p))

elif ord(p) == 97:
    p = ord(p) - 12
    encrypted.append(chr(p))

elif ord(p) == 91:
    p = ord(p) + 11
    encrypted.append(chr(p))

elif ord(p) == 102:
    p = ord(p) - 11
    encrypted.append(chr(p))

elif ord(p) == 89:
    p = ord(p) + 21
    encrypted.append(chr(p))

elif ord(p) == 110:
    p = ord(p) - 21
    encrypted.append(chr(p))

elif ord(p) == 90:
    p = ord(p) + 9
    encrypted.append(chr(p))

elif ord(p) == 99:
    p = ord(p) - 9
    encrypted.append(chr(p))

elif ord(p) == 88:
    p = ord(p) + 20
    encrypted.append(chr(p))

elif ord(p) == 108:
    p = ord(p) - 20
    encrypted.append(chr(p))

elif ord(p) == 92:
    p = ord(p) + 9
    encrypted.append(chr(p))

elif ord(p) == 101:
    p = ord(p) - 9
    encrypted.append(chr(p))

elif ord(p) == 80:
    p = ord(p) + 26
    encrypted.append(chr(p))

elif ord(p) == 106:
    p = ord(p) - 26
    encrypted.append(chr(p))

elif ord(p) == 77:
    p = ord(p) + 16
    encrypted.append(chr(p))

elif ord(p) == 93:
    p = ord(p) - 16
    encrypted.append(chr(p))

elif ord(p) == 73:
    p = ord(p) + 3
    encrypted.append(chr(p))

elif ord(p) == 76:
    p = ord(p) - 3
    encrypted.append(chr(p))

elif ord(p) == 74:
    encrypted.append(chr(p))

elif ord(p) == 119:
    p = ord(p) + 6
    encrypted.append(chr(p))

elif ord(p) == 125:
    p = ord(p) - 6
    encrypted.append(chr(p))

elif ord(p) == 114:
    p = ord(p) + 7
    encrypted.append(chr(p))

elif ord(p) ==121:
    p = ord(p) - 7
    encrypted.append(chr(p))

elif ord(p) == 117:
    p = ord(p) + 6
    encrypted.append(chr(p))

elif ord(p) == 123:
    p = ord(p) - 6
    encrypted.append(chr(p))

elif ord(p) == 115:
    p = ord(p) + 9
    encrypted.append(chr(p))

elif ord(p) == 124:
    p = ord(p) - 9
    encrypted.append(chr(p))

elif ord(p) == 112:
    p = ord(p) + 4
    encrypted.append(chr(p))

elif ord(p) == 116:
    p = ord(p) - 4
    encrypted.append(chr(p))

elif ord(p) == 113:
    p = ord(p) + 9
    encrypted.append(chr(p))

elif ord(p) == 122:
    p = ord(p) - 9
    encrypted.append(chr(p))

elif ord(p) == 118:
    p = ord(p) + 8
    encrypted.append(chr(p))

elif ord(p) == 126:
    p = ord(p) - 8
    encrypted.append(chr(p))

elif ord(p) == 120:
   encrypted.append(chr(p))

print ("".join(encrypted)
#it then executes the code for every character in the sentence entered by the user. When it has done it for every character there is,
#it then prints out the array which stored all the characters that had been worked on. so that you have a jibby jabber.

The char function is used for characters
That is, only one character
The char data type can only store one character in itself
It is used for alphabets and can only store one alphabet at a time.

For example:
char cloth = 's'
So when you put char() and put a number inside its bracket instead of a letter, because the compiler knows char is used for letters but putting a number in its bracket indicated to the compiler that you are trying to find the character whose ASCII number is that number you have put in the bracket
Take for instance, assuming the ASCII number of "a" is 66 right, but I don't know that, I just want to find which letter or symbol has ASCII number of 66

I'll then type "print(char (66))

The computer will automatically print out "a" for me
The ord function is the opposite of the char function
It is used to find out the ASCII number of a character
Take for instance, assuming the ASCII number of "a" is 66 and I don't know that, but I want to find out what the ASCII number of "a" is, I will them type

print(ord("a"))
This is telling the compiler to print out the ASCII number of "a"

The OUTPUT should look like this:
screenshot1.jpg
screenshot.jpg

Proof of work
GITHUB RESPOSITORY

Sort:  

Thank you for your contribution.

  • The tutorial is poorly structured, please be more careful when writing the tutorial.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Yes ill do better next time

Hey @kenechukwu2
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Even though the tutorial was poorly structured I liked it. It was something unique and maybe that's why moderator gave you score. Here's a suggestion that can help you improve your tutorials.

  • Do a series - These single articles doesn't gain much attention if you create a series the audience will increase over time.
  • Improve Formatting - This can only be done by practice but till then I can help you with it. Contact me on Discord before you publish your next tutorial.
  • Create Unique Content - I haven't seen a tutorial like this before so you are already doing it.
  • Put long codes in the Github Repository - I saw that this post has a long block of code. You can just put the code in the Github Repository and point to that.

With that being said, I hope you improve in future and if you need any help contact me on Discord Sneakin#8476

I would like learn about blockchain.development.

I really wants to learn coding but the coding language to understand is very difficult

Posted using Partiko Android

Congratulations @kenechukwu2! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Coin Marketplace

STEEM 0.20
TRX 0.14
JST 0.030
BTC 67657.28
ETH 3498.77
USDT 1.00
SBD 2.70