Port C# of RC4 implementation to Java - #CLOSED#

  • Status: Closed
  • Hadiah: $100
  • Penyertaan diterima: 6
  • Pemenang: SMikhail

Ringkasan Peraduan

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; [login to view URL]
I need a Java version of it so I can encrypt and decrypt text with a given password.

I'll use the form at [login to view URL] 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 [login to view URL];
using [login to view URL];
using [login to view URL];
using [login to view URL];
using [login to view URL];
using [login to view URL];
using [login to view URL];
using [login to view URL];
using [login to view URL];

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)
{
[login to view URL] = password;
[login to view URL] = text;
}

public RC4(string password)
{
[login to view URL] = 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 < [login to view URL]; 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
[login to view URL]([login to view URL](cipherBy));
}
return [login to view URL]();
}

public static string StrToHexStr(string str)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < [login to view URL]; i++)
{
int v = [login to view URL](str[i]);
[login to view URL]([login to view URL]("{0:X2}", v));
}
return [login to view URL]();
}

public static string HexStrToStr(string hexStr)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < [login to view URL]; i += 2)
{
int n = [login to view URL]([login to view URL](i, 2), 16);
[login to view URL]([login to view URL](n));
}
return [login to view URL]();
}

private void RC4Initialize()
{
sbox = new int[N];
int[] key = new int[N];
int n = [login to view URL];
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;
}
}
}
}

Kemahiran Disyorkan

Maklum balas Majikan

“Worked perfectly.”

Gambar Profil jxa, United Kingdom.

Penyertaan teratas dari peraduan ini

Lihat Lagi Entri

Papan Penjelasan Umum

  • jxa
    Penganjur Peraduan
    • 5 years ago

    Thanks for all those that submitted entries but I had to choose the first working entry as I explained I would in the brief.

    • 5 years ago
  • jxa
    Penganjur Peraduan
    • 5 years ago

    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

    • 5 years ago
  • JSLProgrammer
    JSLProgrammer
    • 5 years ago

    Sorry, I don't think it works quite right...

    • 5 years ago
  • JSLProgrammer
    JSLProgrammer
    • 5 years ago

    I have the Java translation for the C# code you provided. If that is all that you wanted I can send it to you. How do you want me to send it to you?

    • 5 years ago
  • JSLProgrammer
    JSLProgrammer
    • 5 years ago

    Do you want the Java program to send data to the webpage or do you just want the functions converted to Java?

    • 5 years ago

Tunjukkan lebih banyak komen

Bagaimana mula dengan peraduan

  • Paparkan peraduan anda

    Paparkan Peraduan Anda Cepat dan mudah

  • Dapatkan berjuta penyertaan

    Dapatkan Bertan-tan Penyertaan Dari serata dunia

  • Anugerahkan penyertaan terbaik

    Anugerahkan penyertaan terbaik Muat turun fail-fail - Mudah!

Paparkan Peraduan Sekarang atau Sertai kami Hari Ini!