cns output
cns output
py
import rsa
def generate_keys():
pubKey =
rsa.pubKey()
with open('keys/pubkey.pem','wb') as
f:
f.write(pubKey.save_pkcs1('PEM')
)
with open('keys/prikey.pem','wb') as
f:
f.write(priKey.save_pkcs1('PEM')
)
def load_keys():
with open('keys/pubkey.pem','rb') as f:
pubKey = rsa.PublicKey.load_pkcs1(f.read())
with open('keys/prikey.pem','rb') as f:
priKey = rsa.PrivateKey.load_pkcs1(f.read())
generate_keys()
pubKey, priKey = load_keys()
if plaintext:
print(f'Plain Text: {plaintext}')
else:
print('Could not decrypt the message')
def generate_keys():
pubKey = rsa.pubKey()
with open('keys/pubkey.pem','wb') as f:
f.write(pubKey.save_pkcs1('PEM'))
with open('keys/prikey.pem','wb') as f:
f.write(priKey.save_pkcs1('PEM'))
def load_keys():
with open('keys/pubkey.pem','rb') as f:
pubKey = rsa.PublicKey.load_pkcs1(f.read())
with open('keys/prikey.pem','rb') as f:
priKey = rsa.PrivateKey.load_pkcs1(f.read())
generate_keys()
pubKey, priKey = load_keys()
if plaintext:
print(f'Plain Text: {plaintext}')
else:
print('Could not decrypt the message')
DES.py
Outputs
PROGRAM:
import
java.io.Buffe
redReader;
import
java.io.IOEx
ception;
import
java.io.Input
StreamRead
er; import
java.util.Sca
nner;
public class CeaserCipher {
static Scanner sc=new Scanner(System.in);
static BufferedReader br = new BufferedReader(new
InputStreamReader(System.in)); public static void main(String[]
args) throws IOException {
// TODO code
application logic
here
System.out.print("
Enter any String:
"); String str =
br.readLine();
System.out.print("
\nEnter the Key:
"); int key =
sc.nextInt();
String encrypted = encrypt(str, key);
System.out.println("\nEncrypted String
is: " +encrypted); String decrypted =
decrypt(encrypted, key);
System.out.println("\nDecrypted String
is: "
+decrypted); System.out.println("\n");
}
public static String encrypt(String str, int key)
if (Character.isUpperCase(c)) {
c = c + (key % 26);
if (c > 'Z') c = c - 26;
}
else if (Character.isLowerCase(c)) {
c = c + (key % 26);
if (c > 'z') c = c - 26;
}
encrypted += (char) c;
}
return encrypted;
}
if (Character.isUpperCase(c)) {
c = c - (key % 26);
if (c < 'A') c = c + 26;
}
else if (Character.isLowerCase(c)) {
c = c - (key % 26);
if (c < 'a') c = c + 26;
}
decrypted += (char) c;
}
return decrypted;
}
// Encryption Process
for (int i = 0; i < 3; i++)
for (int j = 0; j < 1; j++)
for (int k = 0; k < 3; k++)
res[i][j] = res[i][j] + a[i][k] * mes[k][j];
// Decryption Process
inverse();
for (int i = 0; i < 3; i++)
for (int j = 0; j < 1; j++)
for (int k = 0; k < 3; k++)
decrypt[i][j] = decrypt[i][j] + b[i][k] * res[k][j];