assignment_datap_suryanshOri
assignment_datap_suryanshOri
assignment_datap_suryanshOri
Qs)
Code :
#include<iostream>
#include<string>
using namespace std;
int main() {
int key;
string strInp;
cout << "Enter the string here: ";
cin >> strInp;
cout << "Enter the key value: ";
cin >> key;
string enCodedStr;
return 0;
}
Output :
Code:
def encrypt(text, key):
rails = ['' for _ in range(key)]
direction_down = False
row = 0
encrypted_text = ''.join(rails)
return encrypted_text
for i in range(len(cipher)):
rails[row] += '*'
if row == 0:
direction_down = True
elif row == key - 1:
direction_down = False
row += 1 if direction_down else -1
for r in range(key):
for j in range(len(rails[r])):
if rails[r][j] == '*':
rails[r] = rails[r][:j] + cipher[index] +
rails[r][j+1:]
index += 1
result = []
row = 0
direction_down = False
for i in range(len(cipher)):
result.append(rails[row][0])
rails[row] = rails[row][1:]
if row == 0:
direction_down = True
elif row == key - 1:
direction_down = False
row += 1 if direction_down else -1
return ''.join(result)
if __name__ == "__main__":
text = input("Enter the text to be encrypted or
decrypted: ")
key = int(input("Enter the value of key: "))
enOrDe = input("Enter your Choice(E/D): ")
if(enOrDe=='E' or enOrDe=='e'):
encrypted_text = encrypt(text, key)
print(f"Encrypted Text: {encrypted_text}")
elif(enOrDe=='D' or enOrDe=='d'):
decrypted_text = decrypt(text, key)
print(f"Decrypted Text: {decrypted_text}")
else:
print("Incorrect Choice")
Output :
Q3. Write a Python program that defines a function and takes a
password string as input and returns its SHA-256 hashed
representation as a hexadecimal string.
Code:
import hashlib
def hash_password(password):
sha256 = hashlib.sha256()
return sha256.hexdigest()
Output:
Q5. Write a Python program that generates a password using a
random combination of words from a dictionary file.
Code:
import random
def load_words(file_path):
with open(file_path,'r') as file:
words = file.read().splitlines()
return words
def main():
dictionary_file = r'random_words.txt'
words = load_words(dictionary_file)
password = genPass(words)
print(f"Generated Password: {password}")
if __name__ == "__main__":
main()
Output:
Code:
import string
import itertools
import time
def bforce(password):
characters = string.ascii_letters + string.digits +
string.punctuation
attempts = 0
start_time = time.time()
end_time = time.time()
total_time = end_time - start_time
print("Password not found in", attempts, "attempts
and took", total_time, "seconds")
def main():
password = input("Enter the password to be cracked:
")
bforce(password)
if __name__ == "__main__":
main()
Output: