Sponsored By

Sign in to follow this  
iccaros

Math Problem With Enum

Recommended Posts

ok I have a math problem I can not find

here is the code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Basic_Encrytion
{
//The ideal behind this encryption is to mimic the EMIGMA machines of WWII. With the use of diffrent random wheels
//you can create a good enough encrytion, by adding the modifier you are chaning the starting position of the wheel
//Encryption Wheels declaration
public enum WheelOne : int
{ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z }
public enum WheelTwo : int
{ Z, Y, X, W, V, U, T, S, R, Q, P, O, N, M, L, K, J, I, H, G, F, E, D, C, B, A,
z, y, x, w, v, u, t, s, r, q, p, o, n, m, l, k, j, i, h, g, f, e, d, c, b, a }
public enum WheelThree : int
{ a, c, e, g, i, k, m, o, q, s, u, w, y, A, C, E, G, I, K, M, O, Q, S, U, W, Y,
b, d, f, h, j, l, n, p, r, t, v, x, z, B, D, F, H, J, L, N, P, R, T, V, X, Z }
public partial class Form1 : Form
{

//variable declaration
public string DisplayEncrypt = "";
public string DisplayDecrypt = "";


public string encrypt(char RedSideIn, int WheelPosition,int WheelNumber)
{

int BlackSideInt = 0;
int RedSideInStr = (int) Enum.Parse(typeof(WheelOne),Convert.ToString(RedSideIn));
string BlackSideOut = "";
//ensure the pattern loops
if (WheelPosition + RedSideInStr > 51)
BlackSideInt = (WheelPosition + RedSideInStr) - (52);
else if (WheelPosition + RedSideInStr < 0)
BlackSideInt = (WheelPosition + RedSideInStr) + (52);
else
BlackSideInt = WheelPosition + RedSideInStr;

if (WheelNumber == 1)
BlackSideOut = Wheel1(BlackSideInt);
else if (WheelNumber == 2)
BlackSideOut = Wheel2(BlackSideInt);
else if (WheelNumber == 3)
BlackSideOut = Wheel3(BlackSideInt);

return BlackSideOut;

}

private string Wheel3(int BlackSideInt)
{
WheelThree letter = (WheelThree)BlackSideInt;
return letter.ToString("G");
}

private string Wheel2(int BlackSideInt)
{
WheelTwo letter = (WheelTwo)BlackSideInt;
return letter.ToString("G");
}

public string Wheel1(int BlackSideInt)
{
WheelOne letter = (WheelOne)BlackSideInt;
return letter.ToString("G");
}
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

//tokenize input to be sent to encryptor
string TokEncrypt = SourceBox.Text;
int WheelNumber = 0;
for (int x = 0;x < TokEncrypt.Length;x++)
{
// WheelNumber++;
// if (WheelNumber > 3)
// WheelNumber = 1;
DisplayEncrypt = DisplayEncrypt + encrypt(TokEncrypt[x],25,2);

}
EncryptBox.Text = DisplayEncrypt;
WheelNumber = 0;
for (int x = 0; x < DisplayEncrypt.Length; x++)
{
// WheelNumber++;
// if (WheelNumber > 3)
// WheelNumber = 1;
DisplayDecrypt = DisplayDecrypt + encrypt(DisplayEncrypt[x], -25,2);

}
DecryptBox.Text = DisplayDecrypt;


//clean up
DisplayEncrypt = "";
DisplayDecrypt = "";
WheelNumber = 0;
}
}
}

if I choose wheel one it works

if I choose wheel 2 Y&Z and a&b are messed up

if I choose wheel 3 non of it works..

this should be simple pattern matching..

example I use wheel2 and put in abcdefghijklmnopqrstuvwxyz

this is it encrypted Azyxwvutsrqponmlkjihgfedcb

but this is the decrypt YZabcdefghijklmnopqrstuvwx

if I use wheel3 I get this

in: abcdefghijklmnopqrstuvwxyz

encrypt:YbdfhjlnprtvxzBDFHJLNPRTVX

decrypt:YfjnrvzDHLPTXaeimquyCGKOSW

thanks

Share this post


Link to post
Share on other sites

here is the project file VS 2005 type

Basic_Encrytion.zip

Share this post


Link to post
Share on other sites

fixed it, I noticed I was uisng WheelOne for all lookups, makes it hard for the others to decrypt..

here is the fixed code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Basic_Encrytion
{
//The ideal behind this encryption is to mimic the EMIGMA machines of WWII. With the use of diffrent random wheels
//you can create a good enough encrytion, by adding the modifier you are chaning the starting position of the wheel
//Encryption Wheels declaration
public enum WheelOne : int
{ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z }
public enum WheelTwo : int
{ Z, Y, X, W, V, U, T, S, R, Q, P, O, N, M, L, K, J, I, H, G, F, E, D, C, B, A,
z, y, x, w, v, u, t, s, r, q, p, o, n, m, l, k, j, i, h, g, f, e, d, c, b, a }
public enum WheelThree : int
{ a, c, e, g, i, k, m, o, q, s, u, w, y, A, C, E, G, I, K, M, O, Q, S, U, W, Y,
b, d, f, h, j, l, n, p, r, t, v, x, z, B, D, F, H, J, L, N, P, R, T, V, X, Z }
public partial class Form1 : Form
{

//variable declaration
public string DisplayEncrypt = "";
public string DisplayDecrypt = "";


public string encrypt(char RedSideIn, int WheelPosition,int WheelNumber)
{

string BlackSideOut = "";

if (WheelNumber == 1)
BlackSideOut = Wheel1( WheelPosition, RedSideIn);
else if (WheelNumber == 2)
BlackSideOut = Wheel2( WheelPosition, RedSideIn);
else if (WheelNumber == 3)
BlackSideOut = Wheel3( WheelPosition, RedSideIn);

return BlackSideOut;

}

private string Wheel3( int WheelPosition, char RedSideIn)
{
int BlackSideInt = 0;
int RedSideInStr = (int)Enum.Parse(typeof(WheelThree), Convert.ToString(RedSideIn));

//ensure the pattern loops
if (WheelPosition + RedSideInStr > 51)
BlackSideInt = (WheelPosition + RedSideInStr) - (52);
else if (WheelPosition + RedSideInStr < 0)
BlackSideInt = (WheelPosition + RedSideInStr) + (52);
else
BlackSideInt = WheelPosition + RedSideInStr;

WheelThree letter = (WheelThree)BlackSideInt;
return letter.ToString("G");
}

private string Wheel2(int WheelPosition, char RedSideIn)
{
int BlackSideInt = 0;
int RedSideInStr = (int)Enum.Parse(typeof(WheelTwo), Convert.ToString(RedSideIn));

//ensure the pattern loops
if (WheelPosition + RedSideInStr > 51)
BlackSideInt = (WheelPosition + RedSideInStr) - (52);
else if (WheelPosition + RedSideInStr < 0)
BlackSideInt = (WheelPosition + RedSideInStr) + (52);
else
BlackSideInt = WheelPosition + RedSideInStr;

WheelTwo letter = (WheelTwo)BlackSideInt;
return letter.ToString("G");
}

public string Wheel1( int WheelPosition, char RedSideIn)
{
int BlackSideInt = 0;
int RedSideInStr = (int)Enum.Parse(typeof(WheelOne), Convert.ToString(RedSideIn));

//ensure the pattern loops
if (WheelPosition + RedSideInStr > 51)
BlackSideInt = (WheelPosition + RedSideInStr) - (52);
else if (WheelPosition + RedSideInStr < 0)
BlackSideInt = (WheelPosition + RedSideInStr) + (52);
else
BlackSideInt = WheelPosition + RedSideInStr;

WheelOne letter = (WheelOne)BlackSideInt;
return letter.ToString("G");
}

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

//tokenize input to be sent to encryptor
string TokEncrypt = SourceBox.Text;
int WheelNumber = 0;
for (int x = 0;x < TokEncrypt.Length;x++)
{
WheelNumber++;
if (WheelNumber > 3)
WheelNumber = 1;
DisplayEncrypt = DisplayEncrypt + encrypt(TokEncrypt[x],25,WheelNumber);

}
EncryptBox.Text = DisplayEncrypt;
WheelNumber = 0;
for (int x = 0; x < DisplayEncrypt.Length; x++)
{
WheelNumber++;
if (WheelNumber > 3)
WheelNumber = 1;
DisplayDecrypt = DisplayDecrypt + encrypt(DisplayEncrypt[x], -25,WheelNumber);

}
DecryptBox.Text = DisplayDecrypt;


//clean up
DisplayEncrypt = "";
DisplayDecrypt = "";
WheelNumber = 0;
}
}
}

now does anyone have a better way?

I am thinking of advancing the wheelposition so

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this