CODE;
#include <stdio.h>
#include <iostream>
using namespace std;
// returns the encrypted text
string encrypt(string text, int s)
{
string result = "";
// traverse text
for (int i=0;i<text.length();i++)
{
// apply transformation to each
character
// Encrypt Uppercase letters
if (isupper(text[i]))
result +=
char(int(text[i]+s-65)%26 +65);
// Encrypt Lowercase letters
else
result += char(int(text[i]+s-97)%26
+97);
}
// Return the resulting string
return result;
}
// returns the decrypted text
string decrypt(string text, int s)
{
string result = "";
// traverse text
for (int i=0;i<text.length();i++)
{
// apply transformation to each
character
// decryptEncrypt Uppercase
letters
if (isupper(text[i]))
result +=
char(int(text[i]-s-65)%26 +65);
// decrypt Lowercase letters
else
result += char(int(text[i]-s-97)%26
+97);
}
// Return the resulting string
return result;
}
// Driver program to test the above function
int main()
{
string text="IHATECHEGG";
int s = 4;
cout << "Encrypt : " << text;
cout << "\nunsecured: " << text;
cout << "\nsecured: " << encrypt(text,
s);
cout<<"\n";
string ab=encrypt(text, s);
cout << "decrypt : " << ab;
cout << "\nunsecured: " <<ab;
cout << "\nsecured: " <<
decrypt(ab,s);
return 0;
}
output 2
Write a program in python or c++ that has two functions: Function one is called: _encrypt...
1. Write a Python program, in a file called concat_strings.py, that includes the following functions: orderedConcat, a recursive function that takes two alphabetically-ordered strings and merges them, leaving the letters in alphabetical order. Note that the strings may be different lengths. a main method that inputs two ordered strings and calls the orderedConcat method to return a resulting merged, ordered string. Your main method should print the two input strings and the result. Note: You may not use any of...
Python Programing : Convert to binary - functions Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a...
Write a Python function, called counting, that takes two arguments (a string and an integer), and returns the number of digits in the string argument that are not the same as the integer argument. Include a main function that inputs the two values (string and integer) and outputs the result, with appropriate labelling. You are not permitted to use the Python string methods (such as count(), etc.). Sample input/output: Please enter a string of digits: 34598205 Please enter a 1-digit...
IN PYTHON CODE Question #1 Write a function capital that has one argument: strlist that is a list of non-empty strings. If each string in the list starts with a capital letter, then the function should return the value True. If some string in the list does not start with a capital letter, then the function should return the value False You may use any of the string functions that are available in Python in your solution, so you might...
Python: Using chr() and ord() write a function called en_crypt() that takes into input a string and returns a new encrypted version of the input string. Example: "atwOta@0202" should return "fy|TyfE5757", then write a function de_crypt() so that "fy|TyfE5757" returns "atwOta@0202"
(Must be written in Python) You've been asked to write several functions. Here they are: yourName() -- this function takes no parameters. It returns a string containing YOUR name. For example, if Homer Simpson wrote this function it would return "Homer Simpson" quadster(m) -- this function takes a value m that you pass it then returns m times 4. For example, if you passed quadster the value 7, it would return 28. isRratedMovieOK(age) -- this function takes a value age...
1. Write a C++ program called Password that handles encrypting a password. 2. The program must perform encryption as follows: a. main method i. Ask the user for a password. ii. Sends the password to a boolean function called isValidPassword to check validity. 1. Returns true if password is at least 8 characters long 2. Returns false if it is not at least 8 characters long iii. If isValidPassword functions returns false 1. Print the following error message “The password...
C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...
Using python, create a program using nested loops to write a function called substring(s,b) that returns True or False depending on whether or not b is a substring of s. For example: String: "Diamond" Substring: "mond" The code will then state that this is true and "mond" is a substring of "Diamond". Example of what the program should output: Enter string: Tree Enter substring: Tre Yes, 'Tre' is a substring of 'Tree' Limitation: This program cannot use "find()" and "in"...
Python 3: Write a function CharCount, to take a string S and a single character C, and returns the count of C (one letter) in the string S. If the letter of C is not found in S, the function returns -1. You must write your own function to do this and can not use any built-in counting functions. Use the function in main to get two inputs from the user, a sentence and a character, then show the count...