Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C++ code
- //
- void setup()
- {
- Serial.begin(9600);
- Serial.println("Enter Message to Encrypt: ");
- }
- void loop()
- {
- if(Serial.available()>0)
- {
- String message = Serial.readStringUntil('\n');
- message.trim();
- String cip = encrypt(message,400);
- Serial.println(cip);
- Serial.println();
- String pln = decrypt(cip,400);
- Serial.println(pln);
- Serial.println();
- }
- }
- String encrypt(String plain_txt,int key)
- {
- String cipher ="";
- Serial.print("Original Text: ");
- Serial.println(plain_txt);
- Serial.print("Cipher Text: ");
- for(int i=0;i<plain_txt.length();i++)
- {
- cipher += char(plain_txt[i]+ key);
- }
- return cipher;
- }
- String decrypt(String cipher_txt,int key)
- {
- String plain ="";
- Serial.print("Cipher Text: ");
- Serial.println(cipher_txt);
- Serial.print("Plain Text: ");
- for(int i=0;i<cipher_txt.length();i++)
- {
- plain += char(cipher_txt[i] - key);
- }
- return plain;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement