Programming-Basics-Book-CSharp-EN

Problem: String Encryption

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

Example:

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:

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

Testing in the Judge System

Test your solution here: https://judge.softuni.org/Contests/Practice/Index/594#14.