Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1319e69

Browse files
Merge pull request #196 from a6ar55/main
Message encryption with cryptographic hashing algorithm
2 parents a8a7009 + e299bce commit 1319e69

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Message Encryption Project
2+
3+
## Overview
4+
5+
This is a Python project that allows users to encrypt messages with different levels of confidentiality using a variety of encryption techniques and hashing algorithms.
6+
7+
## Features
8+
9+
- **Caesar Cipher Encryption:** Messages can be encrypted using the Caesar cipher, a simple substitution cipher, with different shifts based on the user's specified confidentiality level.
10+
11+
- **Hashing Algorithms:** For higher levels of confidentiality, the project uses different hashing algorithms, such as SHA-256, SHA3-256, and SHA-512, to secure the message.
12+
13+
## Requirements
14+
15+
- Python 3.x
16+
- Python libraries: hashlib (for hashing), cryptography (for symmetric encryption)
17+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import hashlib
2+
3+
def get_confidentiality_level():
4+
while True:
5+
try:
6+
level = int(input("Enter the confidentiality level (1-10): "))
7+
if 1 <= level <= 10:
8+
return level
9+
else:
10+
print("Confidentiality level must be between 1 and 10.")
11+
except ValueError:
12+
print("Please enter a valid integer between 1 and 10.")
13+
14+
def caesar_cipher_encrypt(message, shift):
15+
encrypted_message = ""
16+
for char in message:
17+
if char.isalpha():
18+
if char.islower():
19+
encrypted_message += chr((ord(char) - ord('a') + shift) % 26 + ord('a'))
20+
elif char.isupper():
21+
encrypted_message += chr((ord(char) - ord('A') + shift) % 26 + ord('A'))
22+
else:
23+
encrypted_message += char
24+
return encrypted_message, "Caesar Cipher"
25+
26+
def encrypt_message(message, confidentiality_level):
27+
if 1 <= confidentiality_level <= 2:
28+
# Caesar cipher with a shift of 1 for low confidentiality
29+
shift = 1
30+
encrypted_message, method = caesar_cipher_encrypt(message, shift)
31+
else:
32+
# Choose a suitable hashing algorithm based on the level
33+
if 2 <= confidentiality_level <= 4:
34+
hash_algorithm = hashlib.sha256
35+
elif 4 < confidentiality_level <= 6:
36+
hash_algorithm = hashlib.sha384
37+
elif 6 < confidentiality_level <= 8:
38+
hash_algorithm = hashlib.sha3_256
39+
else:
40+
hash_algorithm = hashlib.sha512
41+
42+
# Hashing the message
43+
hashed_message = hash_algorithm(message.encode()).hexdigest()
44+
encrypted_message, method = hashed_message, hash_algorithm.__name__
45+
46+
return encrypted_message, method
47+
48+
def main():
49+
message = input("Enter the message to be encrypted: ")
50+
confidentiality_level = get_confidentiality_level()
51+
52+
encrypted_message, method = encrypt_message(message, confidentiality_level)
53+
print(f"Encrypted message: {encrypted_message}")
54+
print(f"Encryption method used: {method}")
55+
56+
if __name__ == "__main__":
57+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /