Question

give me a example Develop a set of functions that will allow you to encrypt a...

give me a example
Develop a set of functions that will allow you to encrypt a string using a Caesar cipher.
Develop a set of functions that will allow you to decrypt a string using a Caesar cipher.
Develop a set of functions that will help you to solve (break) a Caesar cipher.

Encrypt, Decrypt, Solve in BASIC 1
Encrypt, Decrypt, Solve in Scala (in a procedural manner)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The encryption can be represented using modular arithmetic by first transforming the letters into numbers, according to the scheme, A = 0, B = 1,…, Z = 25. Encryption of a letter by a shift n can be described mathematically as.

(Encryption Phase with shift n)


(Decryption Phase with shift n)


Examples are :

Text : ABCDEFGHIJKLMNOPQRSTUVWXYZ
Shift: 23
Cipher: XYZABCDEFGHIJKLMNOPQRSTUVW

Text : ATTACKATONCE
Shift: 4
Cipher: EXXEGOEXSRGI


Algorithm for Caesar Cipher:

Input:

  1. A String of lower case letters, called Text.
  2. An Integer between 0-25 denoting the required shift.

Procedure:

  • Traverse the given text one character at a time .
  • For each character, transform the given character as per the rule, depending on whether we’re encrypting or decrypting the text.
  • Return the new string generated.

Encryption and Decryption in scala:

$KEY = "Your KEY";
$IV = "Your IV";
function addpadding($string, $blocksize = 32)
{
    $len = strlen($string);
    $pad = $blocksize - ($len % $blocksize);
    $string .= str_repeat(chr($pad), $pad);
    return $string;
}
function strippadding($string)
{
    $slast = ord(substr($string, -1));
    $slastc = chr($slast);
    $pcheck = substr($string, -$slast);
    if(preg_match("/$slastc{".$slast."}/", $string)){
        $string = substr($string, 0, strlen($string)-$slast);
        return $string;
    } else {
        return false;
    }
}
function encrypt($string = "")
{
    global $KEY,$IV;
    $key = base64_decode($KEY);
    $iv = base64_decode($IV);
    return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key,  addpadding($string), MCRYPT_MODE_CBC, $iv));
}
function decrypt($string = "")
{
    global $KEY,$IV;
    $key = base64_decode($KEY);
    $iv = base64_decode($IV);
    $string = base64_decode($string);
    return strippadding(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_CBC, $iv));
}
Add a comment
Know the answer?
Add Answer to:
give me a example Develop a set of functions that will allow you to encrypt a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • give me a example Develop a set of functions that will allow you to encrypt a...

    give me a example Develop a set of functions that will allow you to encrypt a string using a Caesar cipher. Develop a set of functions that will allow you to decrypt a string using a Caesar cipher. Develop a set of functions that will help you to solve (break) a Caesar cipher. Encrypt, Decrypt, Solve in COBOL Encrypt, Decrypt, Solve in Fortran

  • Cryptography, the study of secret writing, has been around for a very long time, from simplistic...

    Cryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message. One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the...

  • please help solve Computer Eixercise Encrypt the following quote in four-letter blocks, using a. multiplication by 37 modulo 27989898. COMPUTERS ARE USELESS -THEY CAN ONLY GIVE YOU ANSWERS b. Fi...

    please help solve Computer Eixercise Encrypt the following quote in four-letter blocks, using a. multiplication by 37 modulo 27989898. COMPUTERS ARE USELESS -THEY CAN ONLY GIVE YOU ANSWERS b. Find the inverse of 37 in Z27989898 c. The following ciphertext message was encrypted using the method you used in part a (four-letter blocks, multiplication by 37 modulo 27989898). Decrypt the following message to reveal the name of the famous person to whom the quote in part a is attributed. 4589986...

  • please help me to solve (c and d) knowing that d=209 Let the two primes p...

    please help me to solve (c and d) knowing that d=209 Let the two primes p = 41 and q = 17 be given as set-up parameters for RSA. a. Which of the parameters e_1 = 32, e_2 = 49 is a valid RSA exponent? Justify your choice b. Compute the corresponding private key Kpr = (p, q, d). Use the extended Euclidean algorithm for the inversion and point out every calculation step. c. Using the encryption key, encrypt the...

  • Please help me write this Java program. I had posted this question before, but got an...

    Please help me write this Java program. I had posted this question before, but got an answer that was totally wrong. We are using the latest version of Java8. Thank You! -------------------------------------------------------------------------------------- Write a Java program that can successfully DECRYPT a string inputted by the user which has been encrypted using a Caesar Cipher with a unknown shift value(key). You can use brute force to do a for loop through all the 26 shift values, however, your program should only...

  • JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information...

    JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information being exposed, it is becoming more and more important to find ways to protect our sensitive data. In this program we will develop a simple tool that helps users generate strong passwords, encrypt and decrypt data using some cyphering techniques. You will need to create two classes. The first class is your driver for the application and contains the main method. Name this class...

  • Assignment 7: Caesar Cipher Assignment 7 You will create a Caesar cipher which allows the user...

    Assignment 7: Caesar Cipher Assignment 7 You will create a Caesar cipher which allows the user to specify the key and the text to be encrypted. A Caesar cipher is a simple substitution cipher wherein each letter in the message is shifted a certain number of spaces down the alphabet -- this number is called the key. a b c d e f g h i j k l m n o p q r s t u v w...

  • I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text an...

    I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text and key My Current Code is: void SubDecrypt(char *message, char *encryptKey) { int iteration; int iteration_Num_Two = 0; int letter; printf("Enter Encryption Key: \n");                                                           //Display the message to enter encryption key scanf("%s", encryptKey);                                                                   //Input the Encryption key for (iteration = 0; message[iteration] != '0'; iteration++)                               //loop will continue till message reaches to end { letter = message[iteration];                                                      ...

  • Using C++ Part C: Implement the modified Caesar cipher Objective: The goal of part C is...

    Using C++ Part C: Implement the modified Caesar cipher Objective: The goal of part C is to create a program to encode files and strings using the caesar cipher encoding method. Information about the caesar method can be found at http://www.braingle.com/brainteasers/codes/caesar.php.   Note: the standard caesar cipher uses an offset of 3. We are going to use a user supplied string to calculate an offset. See below for details on how to calculate this offset from this string. First open caesar.cpp...

  • Give an example of a set H of hash functions such that h(x) is equally likely...

    Give an example of a set H of hash functions such that h(x) is equally likely to be any element of {0, ..., M − 1} but H is not 2-universal.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT