Question

Caesar's cypher is the simplest encryption algorithm. It adds a fixed value to the ASCII (unicode) value of each cha...

Caesar's cypher is the simplest encryption algorithm. It adds a fixed value to the ASCII (unicode) value of each character of a text. In other words, it shifts the characters. Decrypting a text is simply shifting it back by the same amount, that is, it substract the same value from the characters. Write a Matlab function called caesar that accepts two arguments: the first is the character vector to be encrypted, while the second is the shift amount. The function returns the output argument coded, the encrypted text. The function needs to work with all the visible ASCII characters from space to ~. The ASCII codes of these are 32 through 126. If the shifted code goes outside of this range, it should wrap around. For example, if we shift ~ by 1, the result should be space. If we shift space by -1, the result should be ~.

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

octave:65> shift=1 shift 1 octave:66> charVector=abcd charVector abcd octave:67> disp(cipher(charVector,shift)) bcdeE cipher.m RUN Vars {1x9] ans (abc) charVect # shift function chrAlpha-cipher ( charVector in, shift in) #saving shift to becipher.m RUN Vars {1x9] ans (abc) charVect shift 2 octave:30> shift-2 function chrAlpha-cipher (charVector_in, shift_in) octacipher.m RUN Vars [1x9} ans (abc) charVecto #function takes two arguments (a chr vector and a int variable) 1 #and return a ccipher.m RUN Vars [1x9] ans (abc) charVect # shift #function takes two arguments ( a chr vector and a int variable) functionE cipher.m RUN Vars [1x93 ans (abc) charVect # shift #function takes two arguments (a chr vector and a int variable) #and ret#save the following cipher.m

#function takes two arguments(a chr vector and a int variable)
#and return a char vector
function chrAlpha=cipher(charVector_in,shift_in)
#saving shift to be performed in shift variable
#disp("printing given shift : ");
#shift_in
  
#if shift is morethan 94(126-32) then the following while loop
#take care about preventing more rotational shift
while shift_in>94
shift_in=shift_in-94;
end
  
#saving shift to be performed in shift variable
#disp("printing actual shift to be performed : ");
shift=shift_in;
  
#disp("printing given Character vector: ");
#charVector_in
  
#converting charVector_in to chrarNumeric i.e ASCII eqvivalents
chrarNumeric = uint16(charVector_in);

#disp("printing numeric eqvivalent vector: ");
#chrarNumeric
  
for num =1:length(chrarNumeric)
#check for wrap around
if chrarNumeric(num)+shift>126
chrarNumeric(num)=(chrarNumeric(num)+shift-126+31);
#normal shist
else
chrarNumeric(num)=chrarNumeric(num)+shift;
end
end
#converting new changed chrarNumeric back to character vector
chrAlpha = char(chrarNumeric);
end

#we can call above function directly anywhere by cipher(argument1,argument2)

#where argument1 is character vector and argumne2 is integer

Add a comment
Know the answer?
Add Answer to:
Caesar's cypher is the simplest encryption algorithm. It adds a fixed value to the ASCII (unicode) value of each cha...
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
  • [MATLAB] Write a function called hw4_problem3 that implements the Vigenere cipher. The Vigenere cipher is an...

    [MATLAB] Write a function called hw4_problem3 that implements the Vigenere cipher. The Vigenere cipher is an enhanced version of the Caesar’s cipher: instead of a single shift value, it uses a vector of shifts: the first character of the text is shifted by the first shift value, the second by the second and so on. When we run out of shift values, we go back to the first and start over. The function takes two inputs: txt, a character array...

  • 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...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • Write the programming C please, not C++. The main function should be to find the offset...

    Write the programming C please, not C++. The main function should be to find the offset value of the ciper text "wPL2KLK9PWWZ7K3ST24KZYKfPMKJ4SKLYOKRP4KFKP842LK0ZTY43 " and decrypt it. In cryptography, a Caesar Cipher is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be...

  • 1.     This project will extend Project 3 and move the encryption of a password to a...

    1.     This project will extend Project 3 and move the encryption of a password to a user designed class. The program will contain two files one called Encryption.java and the second called EncrytionTester.java. 2.     Generally for security reasons only the encrypted password is stored. This program will mimic that behavior as the clear text password will never be stored only the encrypted password. 3.     The Encryption class: (Additionally See UML Class Diagram) a.     Instance Variables                                                i.     Key – Integer...

  • Your assignment: 1) Ask the user if we are encrypting or decrypting. 2) Ask the user...

    Your assignment: 1) Ask the user if we are encrypting or decrypting. 2) Ask the user to enter a sentence to be transformed. 3) Ask the user to enter a sentence that will be used as the encryption or decryption key. 4) The sentences (array of characters) should end with a NULL terminator '\0'. 5) The range of values will be all printable characters on the ASCII chart starting with a SPACE - Value 32, up to and including a...

  • C program (Not C++, or C#) Viginere Cipher 1)Ask the user if we are encrypting or...

    C program (Not C++, or C#) Viginere Cipher 1)Ask the user if we are encrypting or decrypting. 2) Ask the user to enter a sentence to be transformed. 3) Ask the user to enter a sentence that will be used as the encryption or decryption key. 4) The sentences (array of characters) should end with a NULL terminator '\0'. 5) The range of values will be all printable characters on the ASCII chart starting with a SPACE - Value 32,...

  • JAVA PROJECT Part 1 - Normalize Text The first thing we will do is normalize the...

    JAVA PROJECT Part 1 - Normalize Text The first thing we will do is normalize the input message so that it’s easier to work with. Write a method called normalizeText which does the following: Removes all the spaces from your text Remove any punctuation (. , : ; ’ ” ! ? ( ) ) Turn all lower-case letters into upper-case letters Return the result. The call normalizeText(“This is some \“really\” great. (Text)!?”) should return “THISISSOMEREALLYGREATTEXT” Part 2 - Obfuscation...

  • create a Java class ShiftCipher The program ShiftCipher should take two inputs from the terminal. The...

    create a Java class ShiftCipher The program ShiftCipher should take two inputs from the terminal. The first should be a string of any length which contains any type of symbol (the plaintext). The second will be a shift value which should be between 0 and 25 inclusive (though you may design your program to be resilient to shifts beyond this value). The program should print the cipher text, in which each of the alphabetic characters in the string is shifted...

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