6.4.
Write a simple encryption program using string functions which apply the substitution method. Here is the given Substitution Table.
Substitution Table: A *
E $
I /
O +
U -‐
Sample input/output dialogue:
Enter message: meet me at 9:00 a.m. in the park
Encrypted message: m$$t m$ *t 9:00 *.m. /n th$ p*rk
using System;
namespace encryption
{
class Program
{
public static void Main(string[] args)
{
string mess, encrypt;
int i;
char[,] Substitution =
{
{ 'A', '*'},
{ 'E', '$'},
{ 'I', '/'},
{ 'O', '+'},
{ 'U', '-'}
};
Console.Write("Enter message: ");
mess = Console.ReadLine();
encrypt = mess;
for (i=0; i < 5; i++)
{
encrypt = encrypt.Replace(Char.ToLower(Substitution[i,0]), Substitution[i,1]);
encrypt = encrypt.Replace(Substitution[i,0], Substitution[i,1]);
}
Console.WriteLine("\nEncrypted message: {0}", encrypt);
Console.Write("\nPress any key to continue . . . ");
Console.ReadKey(true);
}
}
}
Comments
Leave a comment