|
-
May 21st, 2007, 07:59 AM
#1
Thread Starter
Hyperactive Member
'Encryption'
HI, i've c# at school and some kind of noob did 'program' this 'Encryption' way.
Thought I was unable to help him to get rid of these Errors he gets.
Since I really love to know what the answer is.
And NO this is not me asking help.
Im posting this for a clasmate..
Anyhow, Please Help ^^
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;
namespace EncryptionAlgorytmn
{
class Program
{
public string base64Encode(string data)
{
try
{
byte[] encData_byte = new byte[data.Length];
encData_byte = System.Text.Encoding.UTF8.GetBytes(data);
string encodedData = Convert.ToBase64String(encData_byte);
return encodedData;
}
catch (Exception e)
{
throw new Exception("Error in base64Encode" + e.Message);
}
}
public string strReverse(string s)
{
int j = 0;
char[] c = new char[s.Length];
for (int i = s.Length - 1; i >= 0; i--) c[j++] = s[i];
return new string(c);
}
public static string EncryptData(byte[] desKey, byte[] desIV, string data)
{
MemoryStream output = new MemoryStream();
byte[] byteData = new UnicodeEncoding().GetBytes(data);
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
CryptoStream crypt = new CryptoStream(output, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write);
crypt.Write(byteData, 0, byteData.Length);
crypt.Close(); output.Close();
return new UnicodeEncoding().GetString(output.ToArray());
}
static void Main(string[] args)
{
string Encrypted, z;
bool rev;
int x = 1, y = 1;
const string HIDDEN_ENCRYPTION_KEY = "0xF4E";
Console.WriteLine("Enter Password you want to Encrypt:");
Encrypted = Console.ReadLine();
for(int i = 0; i < 10; i++)
{
if (x == 5)
{
x = 1;
}
x++;
switch (x)
{
case 1:
y = 7;
break;
case 2:
y = 2;
break;
case 3:
y = 9;
break;
case 4:
y = 1;
break;
case 5:
y = 6;
break;
default:
y = 0;
break;
}
Encrypted = base64Encode(Encrypted);
if (rev == true)
{
Encrypted = strReverse(Encrypted);
rev = false;
}
else
{
Encrypted = Encrypted + HIDDEN_ENCRYPTION_KEY;
rev = true;
}
if ((i % 2) != 0)
{
Encrypted = EncryptData(x, y, Encrypted);
}
}
z = strReverse(Encrypted);
z = HIDDEN_ENCRYPTION_KEY + Encrypted + HIDDEN_ENCRYPTION_KEY;
Encrypted = (strReverse(z) + strReverse(Encrypted) + HIDDEN_ENCRYPTION_KEY.ToUpper());
Console.Write("Encrypted Key: ");
Console.WriteLine(Encrypted);
Console.Write("Value z: ");
Console.WriteLine(z);
Console.Write("Value rev: ");
Console.WriteLine(rev);
Console.Write("Value x: ");
Console.WriteLine(x);
Console.Write("Value y: ");
Console.WriteLine(y);
Console.ReadKey();
}
}
}
506C65617365205261746520506F7374732E2E2E
-
May 21st, 2007, 06:12 PM
#2
Re: 'Encryption'
 Originally Posted by Iron Skull
I was unable to help him to get rid of these Errors he gets.
What errors would those be? I see code but I see no indication of what errors occurred or where.
-
May 24th, 2007, 03:35 PM
#3
Thread Starter
Hyperactive Member
Re: 'Encryption'
heh, Well I dont know..
Lets try and Compile it :P
Ok, I just did try and compile it.
The Errors are:
The best overloaded method match for 'EncryptionCSharp.Program.EncryptData(byte[], byte[], string)' has some invalid arguments
Argument '2': cannot convert from 'int' to 'byte[]'
An object reference is required for the nonstatic field, method, or property 'EncryptionCSharp.Program.strReverse(string)'
'int' to 'byte[]' must be posable to fix by Googleing it. Ill look for that one :P
But the others..? No idea..
506C65617365205261746520506F7374732E2E2E
-
May 24th, 2007, 05:49 PM
#4
Re: 'Encryption'
Well this is an example of why you should use descriptive variable names and comment your code. I have no idea what 'x' and 'y' are supposed to be. We shouldn't have to analyse every line of code to work out what a variable does.
As for the error regarding strReverse, you're calling it from a static method when it's not static itself. There is no current instance in a static method so you can't just call an instance method on the current instance. You have to either call strReverse on an instance of the Program class or else decalre the strReverse method as static as well.
-
May 25th, 2007, 12:36 AM
#5
Fanatic Member
Re: 'Encryption'
you could try a convert.tobyte(fill in your int var here)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|