Who can help me?

S

Stefan

Hello!
(Sorry for my bad english :) )

I have a large problem because i have no idea programming in C++ and have to
port the following code as soon as possible to Java.
who can help me?

The code decodes and encodes a password.

Bsp:
g_UserPass = 99999;
g_RealPass = 55ioPQZab

The decoded result:
IYJTKODVEKLLITHMBQ

//===========================================================================
// File: MyRand.h
// Desc: Random generator used in crypting algorithms
//===========================================================================

#pragma once
#include "FileBuffer.h"
#define MAX_STRING_LEN 1023

class CMyRand
{
// Data: seed # 1
DWORD randval;
// Data: seed # 2
DWORD randvalor;

public:
// ctor:
CMyRand();

// Method: Sets starting seed of generator
__forceinline void SetSeed(DWORD dwSeed)
{
randval = dwSeed;
randvalor = 13;
};

// Method: Gets next random value using current seed
// and changes seed to generate next value
__forceinline DWORD GetRand()
{
if( (randval & 0xFFFFFFFE) == 0)
randval = randval ^ 1;

if( (randval & 1) == 1)
randval = (randval / 2) ^ 0xEDB88320;
else
randval = randval / 2;

randvalor *= 5;
randvalor++;
return randval ^ randvalor;
};
};


//===========================================================================
// File: MyRand.cpp
// Desc: Random generator used in crypting algorithms
//===========================================================================

#include "stdafx.h"
#include "myrand.h"

//===========================================================================
// Implementation of class CMyRand
//===========================================================================

CMyRand::CMyRand():randval(0),randvalor(13)
{
}

Und dann sind da noch zwei Methoden, die zum verschlüsseln und entschlüsseln
zuständig sind...
//===========================================================================
//===========================================================================
void Encode()
{
g_UserPass = L"";
CMyRand rg;
rg.SetSeed( g_PKZ);

for ( int i = 0; i < g_RealPass.GetLength(); i++){
BYTE b0 = BYTE( g_RealPass.GetAt(i) ^ rg.GetRand() );

int _low = b0 & 0x0F;
int _high = (b0>>4) & 0x0F;
TCHAR ch1 = _low + 'A';
TCHAR ch2 = 'Z' - _high;

g_UserPass += ch1;
g_UserPass += ch2;
}
}

void Decode()
{
g_CheckPass = L"";

CMyRand rg;
rg.SetSeed( g_PKZ );

for ( int i = 0; i < g_UserPass.GetLength(); i += 2 ){
TCHAR ch1 = g_UserPass.GetAt(i);
TCHAR ch2 = g_UserPass.GetAt(i + 1);

int _low = ch1 - 'A';
int _high = 'Z' - ch2;

BYTE b0 = (_low & 0x0F) | ((_high << 4) & 0xF0);
TCHAR tc0 = TCHAR( b0 ^ rg.GetRand() );
g_CheckPass += tc0;
}
}

Thanks for your help!
 
P

Phlip

Stefan said:
I have a large problem because i have no idea programming in C++ and have to
port the following code as soon as possible to Java.
who can help me?

The code decodes and encodes a password.

Take the unit tests for this, and convert them to Java, in order from
easiest to hardest. Make each pass, in Java.

You do have unit tests, don't you? If not, write them, using CppUnit. Then
switch to JUnit.
 
T

tbs

Stefan said:
Hello!
(Sorry for my bad english :) )

I have a large problem because i have no idea programming in C++ and have to
port the following code as soon as possible to Java.
who can help me?

The code decodes and encodes a password.

Bsp:
g_UserPass = 99999;
g_RealPass = 55ioPQZab

The decoded result:
IYJTKODVEKLLITHMBQ

//===========================================================================
// File: MyRand.h
// Desc: Random generator used in crypting algorithms
//===========================================================================

#pragma once
#include "FileBuffer.h"
#define MAX_STRING_LEN 1023

class CMyRand
{
// Data: seed # 1
DWORD randval;
// Data: seed # 2
DWORD randvalor;

public:
// ctor:
CMyRand();

// Method: Sets starting seed of generator
__forceinline void SetSeed(DWORD dwSeed)
{
randval = dwSeed;
randvalor = 13;
};

// Method: Gets next random value using current seed
// and changes seed to generate next value
__forceinline DWORD GetRand()
{
if( (randval & 0xFFFFFFFE) == 0)
randval = randval ^ 1;

if( (randval & 1) == 1)
randval = (randval / 2) ^ 0xEDB88320;
else
randval = randval / 2;

randvalor *= 5;
randvalor++;
return randval ^ randvalor;
};
};


//===========================================================================
// File: MyRand.cpp
// Desc: Random generator used in crypting algorithms
//===========================================================================

#include "stdafx.h"
#include "myrand.h"

//===========================================================================
// Implementation of class CMyRand
//===========================================================================

CMyRand::CMyRand():randval(0),randvalor(13)
{
}

Und dann sind da noch zwei Methoden, die zum verschlüsseln und entschlüsseln
zuständig sind...
//===========================================================================
//===========================================================================
void Encode()
{
g_UserPass = L"";
CMyRand rg;
rg.SetSeed( g_PKZ);

for ( int i = 0; i < g_RealPass.GetLength(); i++){
BYTE b0 = BYTE( g_RealPass.GetAt(i) ^ rg.GetRand() );

int _low = b0 & 0x0F;
int _high = (b0>>4) & 0x0F;
TCHAR ch1 = _low + 'A';
TCHAR ch2 = 'Z' - _high;

g_UserPass += ch1;
g_UserPass += ch2;
}
}

void Decode()
{
g_CheckPass = L"";

CMyRand rg;
rg.SetSeed( g_PKZ );

for ( int i = 0; i < g_UserPass.GetLength(); i += 2 ){
TCHAR ch1 = g_UserPass.GetAt(i);
TCHAR ch2 = g_UserPass.GetAt(i + 1);

int _low = ch1 - 'A';
int _high = 'Z' - ch2;

BYTE b0 = (_low & 0x0F) | ((_high << 4) & 0xF0);
TCHAR tc0 = TCHAR( b0 ^ rg.GetRand() );
g_CheckPass += tc0;
}
}

Thanks for your help!

Do your own homework.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top