- Freelancer
- Concurso
- .NET
- Port C# of RC4 implementation to Java - #CLOSED#
Port C# of RC4 implementation to Java - #CLOSED#
- Estado: Closed
- Prêmio: $100
- Inscrições Recebidas: 6
- Vencedor: SMikhail
Síntese do concurso
I've have received a working version, so no more entries please.
I'm going to do further tests then I'll end the contest. Thanks J
----------------------------------------------------
Port the C# below into Java
The C# code below as described at; [url removed, login to view]
I need a Java version of it so I can encrypt and decrypt text with a given password.
I'll use the form at [url removed, login to view] to test it with a few different text & Password values
I need this ASAP so I'll choose the first working answer submitted.
Thanks
-----------------------------------------------------------------------------
using System;
using [url removed, login to view];
using [url removed, login to view];
using [url removed, login to view];
using [url removed, login to view];
using [url removed, login to view];
using [url removed, login to view];
using [url removed, login to view];
using [url removed, login to view];
using [url removed, login to view];
namespace TestRC4
{
public class RC4
{
private const int N = 256;
private int[] sbox;
private string password;
private string text;
public RC4(string password, string text)
{
[url removed, login to view] = password;
[url removed, login to view] = text;
}
public RC4(string password)
{
[url removed, login to view] = password;
}
public string Text
{
get { return text; }
set { text = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public string EnDeCrypt()
{
RC4Initialize();
int i = 0, j = 0, k = 0;
StringBuilder cipher = new StringBuilder();
for (int a = 0; a < [url removed, login to view]; a++)
{
i = (i + 1) % N;
j = (j + sbox[i]) % N;
int tempSwap = sbox[i];
sbox[i] = sbox[j];
sbox[j] = tempSwap;
k = sbox[(sbox[i] + sbox[j]) % N];
int cipherBy = ((int)text[a]) ^ k; //xor operation
[url removed, login to view]([url removed, login to view](cipherBy));
}
return [url removed, login to view]();
}
public static string StrToHexStr(string str)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < [url removed, login to view]; i++)
{
int v = [url removed, login to view](str[i]);
[url removed, login to view]([url removed, login to view]("{0:X2}", v));
}
return [url removed, login to view]();
}
public static string HexStrToStr(string hexStr)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < [url removed, login to view]; i += 2)
{
int n = [url removed, login to view]([url removed, login to view](i, 2), 16);
[url removed, login to view]([url removed, login to view](n));
}
return [url removed, login to view]();
}
private void RC4Initialize()
{
sbox = new int[N];
int[] key = new int[N];
int n = [url removed, login to view];
for (int a = 0; a < N; a++)
{
key[a] = (int)password[a % n];
sbox[a] = a;
}
int b = 0;
for (int a = 0; a < N; a++)
{
b = (b + sbox[a] + key[a]) % N;
int tempSwap = sbox[a];
sbox[a] = sbox[b];
sbox[b] = tempSwap;
}
}
}
}
Habilidades Recomendadas
Feedback do Empregador
“Worked perfectly.”
jxa, United Kingdom.
Principais inscrições deste concurso
-
SMikhail Russian Federation
-
sanart India
-
narendragautam India
-
narendragautam India
-
krutikjayswal India
-
Propanoff Russian Federation
Painel de Esclarecimento Público
Como começar com concursos
-
Poste seu Concurso Rápido e fácil
-
Obtenha Toneladas de Inscrições De todo o mundo
-
Premie a melhor inscrição Baixe os arquivos - fácil!