Practical 1: Encryption, Decryption and Hashing

===== SOURCE: Encrypt_decrypt_&_Hashing_algo.docx =====

Prac 1:-Encrypt and decrypt algo 


Code:-

def encrypt(text,s):
    result=""
    for i in range(len(text)):
        char=text[i]
        if (char.isupper()):
            result+=chr((ord(char) + s-65) % 26 +65)
        else:
            result+=chr((ord(char) + s-97) % 26 +97)

    return result


def decrypt(text,s):
    result=""
    for i in range(len(text)):
        char=text[i]
        if (char.isupper()):
            result+=chr((ord(char) - s-65) % 26 +65)
        else:
            result+=chr((ord(char) - s-97) % 26 +97)

    return result


text="attackontitan"
s=5
print("text is:",text)
print("shift of:",s)
print("encrypted result:",encrypt(text,s))
de=encrypt(text,s)

print(decrypt(de,s))


Output:-




2.Hashing
import bcrypt

pwd=b'Mypass'

salt=bcrypt.gensalt()

hashed=bcrypt.hashpw(pwd,salt)

print("Salt :")
print(salt)

print("Hashed")

print(hashed)


Output:-