<$BlogRSDURL$>
Ankh Morpork's Finest Coder
Wednesday, March 09, 2005

Homework Sucks!
Just thought you should know...HOMEWORK SUCKS! I was so bored with the hwk that I decided to write a program to do some very meanial work. Thats for question 1. This is horrible code. Don't ever write this. I'm bored and desperate so i'm excused. Besides, the grader is not looking for code. I'm gonna include it just because I can. I'm CS goddamit! I WILL WRITE CODE! THAT IS MY MANIFESTO! EVERY HOMEWORK WILL HAVE CODE IN IT!

using System;
using System.Collections;


public class MyClass
{
public static void Main()
{
string s = "SENDMOREMONEY";
string e = "CASHNOTNEEDED";
int [] x = {9, 0, 1, 7, 23, 15, 21, 14, 11, 11, 2, 8, 9};
ArrayList encryptResult = new ArrayList();

Encrypt(ref s, ref x, ref encryptResult);

Console.WriteLine("\n\n");
Console.Write("Decryption Pad \t= ");
for(int i = 0; i < e.Length; i++)
{
char c = e[i];
int want = (int)c - 64;

int have = (int)encryptResult[i];

int res = want - have;

if(res < 0)
res = 26 + res;

Console.Write(res + " " );
}

int w = Console.Read();
}

public static void Encrypt(ref string s, ref int[] x, ref ArrayList list1)
{
if(s.Length == x.Length)
{
ArrayList list = new ArrayList();


Console.Write(s + "\t= ");
for(int i = 0; i < s.Length; i++)
{
char c = s[i];
int curr = (int)c - 64;
list.Add(curr);
Console.Write(curr + " ");
}

Console.WriteLine();
Console.Write("Pad \t\t= ");
foreach(int y in x)
{
Console.Write(y + " ");
}

Console.WriteLine();
Console.Write("Encrypted \t= ");
for(int j = 0; j < list.Count; j++)
{
int y = (int)list[j];
int next = (y + x[j]) % 26;
char c = (char)(next + 64);
list1.Add(next);
Console.Write( c + " ");
}
}
}
}

0 Comments:

Post a Comment