Write a method Encrypt(char letter), which encrypts a given letter in the following way: It takes the first and the last digit from the ASCII code of the letter and concatenates them into a string, which will represent the result. In the beginning of the string, which represents the result, we will insert the symbol which matches the following condition: ASCII code of the letter + the last digit of the ASCII code of the letter. After that in the end of the string, which represents the result, you concatenate the character which matches the following condition: ASCII code of the letter - the first digit of the ASCII code of the letter. The method should return the encrypted string. Example: j → p16i ASCII code of j is 106 → First digit – 1, last digit – 6. We concatenate the first and the last digit → 16. At the beginning of the string, which represents the result, concatenate the symbol, which you get from the sum of the ASCII code + the last digit → 106 + 6 → 112 → p. At the end of the string, which represents the result, concatenate the symbol, which you get from subtracting the ASCII code – the first digit → 106 - 1 → 105 → i. Using the method shown above, write a program which takes a sequence of characters, encrypts them and prints the result on one line. The input data will always be valid. The Main method must read the data given by the user – an integer n, followed by a character for each of the following n lines. Encrypt the symbols and add them to the encrypted string. In the end, as a result, you must print an encrypted string as in the following example. Example: S, o, f, t, U, n, i → V83Kp11nh12ez16sZ85Mn10mn15h Sample Input and Output Input Output 7 S o f t U n i V83Kp11nh12ez16sZ85Mn10mn15h Input Output 7 B i r a H a x H66

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

 

PLEASE NOTE: IT'S A TEXT BOOK EXERCISE.

BOOK NAME: Fundamentals of Computer Programming with Programming Basics with C# (English)

Problem: String Encryption

Write a method Encrypt(char letter), which encrypts a given letter in the following way:

  • It takes the first and the last digit from the ASCII code of the letter and concatenates them into a string, which will represent the result.
  • In the beginning of the string, which represents the result, we will insert the symbol which matches the following condition:
    • ASCII code of the letter + the last digit of the ASCII code of the letter.
  • After that in the end of the string, which represents the result, you concatenate the character which matches the following condition:
    • ASCII code of the letter - the first digit of the ASCII code of the letter.
  • The method should return the encrypted string.

Example:

  • j → p16i
    • ASCII code of j is 106 → First digit – 1, last digit – 6.
    • We concatenate the first and the last digit → 16.
    • At the beginning of the string, which represents the result, concatenate the symbol, which you get from the sum of the ASCII code + the last digit → 106 + 6 → 112 → p.
    • At the end of the string, which represents the result, concatenate the symbol, which you get from subtracting the ASCII code – the first digit → 106 - 1 → 105 → i.

Using the method shown above, write a program which takes a sequence of charactersencrypts them and prints the result on one line.

The input data will always be valid. The Main method must read the data given by the user – an integer n, followed by a character for each of the following n lines.

Encrypt the symbols and add them to the encrypted string. In the end, as a result, you must print an encrypted string as in the following example.

Example:

  • S, o, f, t, U, n, i → V83Kp11nh12ez16sZ85Mn10mn15h

Sample Input and Output

Input Output
7
S
o
f
t
U
n
i
V83Kp11nh12ez16sZ85Mn10mn15h
Input Output
7
B
i
r
a
H
a
x
H66<n15hv14qh97XJ72Ah97xx10w

Hints and Guidelines

Firstly, we will give a value of string.Empty to the string, which will keep the result. We must recur a loop n times, so that in each iteration we will add the encrypted symbol to the result string.

In order to find the first and the last digit of the ASCII code, we will use the same algorithm that we used to solve "Integer to Base".

References:

  • Title: Programming Basics with C#
  • Authors: Svetlin Nakov & Team
  • ISBN: 978-619-00-0902-3 (9786190009023)
  • Edition: Faber Publishing, Sofia, 2019
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY