 |
|
 |
Awesome .
Thank you very much for this!
Cedric D.
|
|
|
|
 |
|
 |
Hi. What does this line do?
RC4Engine.cs 82 output[offset] = (byte)((int)a^(int)b);
Appreciate the help. Thank you
|
|
|
|
 |
|
 |
I was using this RC4 algorithm since years in my application.
It was working fine with .NET 1.1
But when I have converted my application to .NET 3.5, it was having problem decrypting the values.
I have debugged the code and observed that It was not able to decrypt the 2nd character always.
E.g. If I have encrypted the word "ABCDE", then while Decrypting the encrypted value, it is giving all the coorect values for A , C, D, E but not the 'B'.
It was returning some value like 'A��CDE'.
Any idea about this?
Please Help...!!!
|
|
|
|
 |
|
 |
this is great. but how am i able to get this
currently having a project which needed this. but i cant seem to get this. someone pls tell me .thank you .
cliff_khoo@hotmail.com
if u can e mail me it will be faster
|
|
|
|
 |
|
 |
Hello,
I am a developer working for a commercial software company. I am interested in adapting source code found in this article. Can you tell me if there are license or copyright terms with which I must comply?
RC4 Encryption Algorithm: C# Version
Thanks for much for your help.
J Wilson
|
|
|
|
 |
|
 |
Feel free do to it.
Ciao,
Simone
|
|
|
|
 |
|
 |
Here is another implementation:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace RC4
{
public class RC4
{
private byte[] K;
private byte[] S;
public byte[] State
{
get { return this.S; }
}
public RC4(string key)
{
this.K = StringToByteArray(key);
}
public RC4(byte[] key)
{
this.K = key;
}
public void KeySchedule()
{
this.S = new byte[this.K.Length];
for (int i = 0; i < this.S.Length; i++)
{
this.S[i] = (byte)i;
}
int j = 0;
for (int i = 0; i < this.S.Length; i++)
{
j = (j + this.K[i % K.Length] + this.S[i]) % this.S.Length;
this.Swap(i, j);
}
}
private int i = 0;
private int j = 0;
public byte Loop()
{
i = (i + 1) % this.S.Length;
j = (j + S[i]) % this.S.Length;
System.Windows.Forms.MessageBox.Show(j + "");
this.Swap(i, j);
byte z = this.S[(this.S[i] + this.S[j]) % this.S.Length];
return z;
}
public byte Encrypt(byte input)
{
return (byte)(this.Loop() ^ input);
}
private void Swap(int i, int j)
{
byte tmp = this.S[i];
this.S[i] = this.S[j];
this.S[j] = tmp;
}
private static byte[] StringToByteArray(string input)
{
ASCIIEncoding encoding = new ASCIIEncoding();
return encoding.GetBytes(input);
}
}
}
|
|
|
|
 |
|
 |
very interesting.
did you can post a little snipet code on how to use it, please.
thanks in advance!
|
|
|
|
 |
|
 |
I need the c# code for making key generation , encryption and decryption in RSA algorithm
|
|
|
|
 |
|
 |
// original from sf under GNU LESSER GENERAL PUBLIC LICENSE // http://sourceforge.net/projects/rc4dotnet // simplified by me and fixed for files using System; using System.IO; using System.Text; namespace Encryption.LESR_RC4_Geffe { public interface ICoder { void Encrypt(string password, string file, string targetFile); void Decrypt(string password, string file, string targetFile); } public class RC4: ICoder { private const int EncodingCode = 1251; public void Encrypt(string password, string file, string targetFile) { byte[] content = encrypt(password, File.ReadAllBytes(file)); File.WriteAllBytes(targetFile, content); } public void Decrypt(string password, string file, string targetFile) { byte[] content = encrypt(password, File.ReadAllBytes(file)); File.WriteAllBytes(targetFile, content); } private int getAsciiCode(char character) { return (int)(Encoding.GetEncoding(EncodingCode).GetBytes(character + "")[0]); } private char fromAsciiCode(int asciiCode) { byte[] bytes = new byte[1]; bytes[0] = (byte)asciiCode; return Encoding.GetEncoding(EncodingCode).GetString(bytes)[0]; } private string hexToBinary(string packtype, string datastring) { int i, j, datalength, packsize; byte[] bytes; char[] hex; string tmp; datalength = datastring.Length; packsize = (datalength/2) + (datalength % 2); bytes = new byte[packsize]; hex = new char[2]; for (i = j = 0; i < datalength; i+=2) { hex[0] = datastring[i]; if (datalength - i == 1) hex[1] = '0'; else hex[1] = datastring[i + 1]; tmp = new string(hex, 0, 2); try { bytes[j++] = byte.Parse(tmp, System.Globalization.NumberStyles.HexNumber); } catch {} /* grin */ } return Encoding.GetEncoding(EncodingCode).GetString(bytes); } public string binaryToHex(string bindata) { int i; byte[] bytes = Encoding.GetEncoding(EncodingCode).GetBytes(bindata); string hexString = ""; for (i = 0; i < bytes.Length; i++) { hexString += bytes[i].ToString("x2"); } return hexString; } private byte[] encrypt(string password, byte[] data) { int a, i, j, k, tmp, pwd_length, data_length; int[] key, box; byte[] cipheredText; password = hexToBinary("H*", password); // valid input, please! pwd_length = password.Length; data_length = data.Length; key = new int[256]; box = new int[256]; cipheredText = new byte[data.Length]; for (i = 0; i < 256; i++) { key[i] = getAsciiCode(password[i % pwd_length]); box[i] = i; } for (j = i = 0; i < 256; i++) { j = (j + box[i] + key[i]) % 256; tmp = box[i]; box[i] = box[j]; box[j] = tmp; } for (a = j = i = 0; i < data_length; i++) { a = (a + 1) % 256; j = (j + box[a]) % 256; tmp = box[a]; box[a] = box[j]; box[j] = tmp; k = box[((box[a] + box[j]) % 256)]; cipheredText[i] = (byte)(data[i] ^ k); } return cipheredText; } } }
|
|
|
|
 |
|
 |
And even simpler - with all language symbols namespace Encryption.LESR_RC4_Geffe { public class RC4: ICoder { private const int EncodingCode = 1251; public void Encrypt(string password, string file, string targetFile) { byte[] passwordToPass = System.Text.Encoding.Default.GetBytes(password); byte[] content = encrypt(passwordToPass, File.ReadAllBytes(file)); File.WriteAllBytes(targetFile, content); } public void Decrypt(string password, string file, string targetFile) { Encrypt(password, file, targetFile); } private byte[] encrypt(byte[] password, byte[] data) { int a, i, j, k, tmp, pwd_length, data_length; int[] key, sbox; byte[] cipheredData; pwd_length = password.Length; data_length = data.Length; key = new int[256]; sbox = new int[256]; cipheredData = new byte[data.Length]; for (i = 0; i < 256; i++) { key[i] = password[i % pwd_length]; sbox[i] = i; } for (j = i = 0; i < 256; i++) { j = (j + sbox[i] + key[i]) % 256; tmp = sbox[i]; sbox[i] = sbox[j]; sbox[j] = tmp; } for (a = j = i = 0; i < data_length; i++) { a = (a + 1) % 256; j = (j + sbox[a]) % 256; //swap tmp = sbox[a]; sbox[a] = sbox[j]; sbox[j] = tmp; k = sbox[((sbox[a] + sbox[j]) % 256)]; cipheredData[i] = (byte)(data[i] ^ k); } return cipheredData; } } }
|
|
|
|
 |
|
 |
Thanks Simone for this article, but actually I have a comment about the algorithm implementation,
you are using 'mod 255', while I've read the algorithm before & it says to use 'mod 256'
that differs in the output completely, so do you have any explanation for wt you've done or that was a mistake?
Thanks,
|
|
|
|
 |
|
 |
I agree, I think line 266 of RC4Engine.cs should be:
static public long m_nBoxLen = 256;
|
|
|
|
 |
|
 |
hello.....i`m now doing my final year project in my university.....and i have to do the encryption and decryption via the PIC microcontroller....could anyone help me how could i do my project or any references or tutorial.....I`m gonna do it in C language programming.......
|
|
|
|
 |
|
 |
Hello,
This code doesn't seem to encrypt/decrypt the unicode (chinese/japanese) characters correctly. Is there anything that needs to be modified in order to make that work ?
Thanks in advance.
|
|
|
|
 |
|
 |
This algorithm does not produce correct outputs. Should not be used. Instead another .NET library http://rc4dotnet.devhome.org
|
|
|
|
 |
|
 |
Can you explain me why???
Thanks in Advance
|
|
|
|
 |
|
 |
Change this line of code, I think it will work.
static public long m_nBoxLen = 256;
|
|
|
|
 |
|
 |
Thanks man!
Your example was exactly what I was looking for. A small and simple (and working) encryption class for a small and simple tool that needs to hide a password in its settings file. All the other examples I've found using Microsoft's encryption API were just too complicated for a beginner. You've really made my day!
Cheers
Christian
|
|
|
|
 |
|
 |
I can't encript the following frase
Estos fabio ay dolor que ves ahora campos de soledad mustio collado fueron otrora
When you encrypt it it loses part of the message and when you decipher you got only
Estos fabio ay
By
Orestes
|
|
|
|
 |
|
 |
AntoninoLuis wrote: When you encrypt it it loses part of the message and when you decipher you got only
It's a bug of the interface: it doesn't display all the crypted phrase. The encryption class works fine : if you want to test it you have to debug the project and set breakpoint to line 314/315 of frmFrontend.cs.
Hope it heps.
Simone
|
|
|
|
 |
|
 |
I don't know much about encryption, but I found it really easy to add your class to my Delphi .NET project and encrypt some data. Good work. Thank you
|
|
|
|
 |
|
 |
Which is faster RSA, ECC, DES, or RC4? I know symmetric enc. is faster so I think it's RC4, but wanted to double check.
Can RC4 be used in either CBC or ECB mode?
Can RC4 be us as a public key algorithm?
thanks!
|
|
|
|
 |
|
 |
That's a pretty dumb question. Google the internet for answers before asking something like this. ROFLOLMFAO
|
|
|
|
 |
|
 |
I want code encript password
mailto:lethanhdaobk@yahoo.com
|
|
|
|
 |