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!
(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!