Code: Select all
#library "ZCOIN"
#include "zcommon.acs"
#define MAXCOINS 1024
int Coins[MAXCOINS][5];
int Difficult = 30;
int Key = 1;
function int AND(int a, int b) {
return a & b;
}
function int OR(int a, int b) {
return a | b;
}
function int INVERT(int source) {
int i = 0;
int j = 0;
while (j < 32) {
i = OR(i,(1 << j) - AND(source, 1 << j));
j++;
}
return i;
}
function int COPYBITS(int source, int index, int length, int newindex) {
int i = 0;
int j = 0;
int i2 = 0;
// printf("start - index %d length %d newindex %d\n", index, length, newindex);
// printBits("debug input", sizeof(source), &source);
while (j < 32) {
if (j > (index) - length && j <= (index)) {
i = OR(i, AND(source, 1 << j));
}
j++;
}
// printBits("debug", sizeof(i), &i);
if (index > newindex) {
i = i >> (index - newindex);
}
else {
i = i << (newindex - index);
}
// printBits("debug", sizeof(i), &i);
j = newindex - length;
while (j <= newindex) {//there may have some bit shift trash after that
i2 = OR(i2, AND(i, 1 << j));
j++;
}
// printBits("debug", sizeof(i2), &i2);
// printf("end\n");
return i2;
}
script "CheckCoins" (void) NET{
int total=0;
for(int i=0; i < MAXCOINS;i++){
if(Coins[i][0] == 0){
total = i;
i = 1024;
}
}
LOG(s:"Total earned coins:",d:total);
}
script "CheckCoinsServer" (void){
int total=0;
for(int i=0; i < MAXCOINS;i++){
if(Coins[i][0] == 0){
total = i;
i = 1024;
}
else{
LOG(s:"Coin ",d:i,s:" Key = ",d:Coins[i][1],s:" ",d:Coins[i][2],s:" ",d:Coins[i][3]);
}
}
LOG(s:"Total earned coins:",d:total);
}
script "FirstRun" open{
LOG(s:"Zandrocoin - created by ibm5155");
acs_namedexecutealways("mAdeek",0,Difficult);
acs_namedexecute("UpdateClientKey",0,(Key >> 16) | !(Key << 16),!Key,!(Key >> 16) | (Key << 16));
}
script "GetNewCoin" (int X0, int X1, int X2,int X3) NET{
//validate if we received a valid key (not cheat)
int i = -1;
int a;
if (COPYBITS(X0, 31, 4, 4) == COPYBITS(X0, 7, 4, 4)) {
if (COPYBITS(X0, 27, 4, 4) == COPYBITS(INVERT(X0), 3, 4, 4)) {
if (COPYBITS(X2, 31, 1, 0) == COPYBITS(X2, 0, 1, 0) && COPYBITS(X2, 31, 1, 0) == COPYBITS(INVERT(X2), 16, 1, 0)) {
if (COPYBITS(X3, 15, 2, 2) == COPYBITS(X3, 9, 2, 2)) {
//now compare if each key is valid with each other
if (COPYBITS(X0, 21, 2, 2) == COPYBITS(X1, 7, 2, 2)) {
if (COPYBITS(X0, 23, 1, 2) == COPYBITS(INVERT(X2), 17, 1, 2)) {
if (COPYBITS(X2, 21, 2, 2) == COPYBITS(INVERT(X3), 20, 2, 2)) {
if (COPYBITS(X0, 6, 1, 1) == COPYBITS(INVERT(X3), 21, 1, 1)) {
for (i = 0; i < MAXCOINS; i++) {
if (Coins[i][0] == 0) {
Coins[i][0] = 1;
Coins[i][1] = X0;
Coins[i][2] = X1;
Coins[i][3] = X2;
Coins[i][4] = X3;
i = 1024;
}
}
Key++;
Difficult++;
acs_namedexecutealways("mAdeek",0,Difficult);
acs_namedexecutealways("UpdateClientKey",0, (Key >> 16) | !(Key << 16), !Key, !(Key >> 16) | (Key << 16) );
printbold(s:"New coin found by ",n:activatortid());
}
}
}
}
}
}
}
}
/*
if(i == -1){
if(ActivatorTid() == -1){
printbold(s:"Server is trying to cheat!!!");
}
else{
printbold(n:activatortid(),s:" is trying to cheat!!!");
}
}
*/
}
script "mAdeek" (int a) clientside{
Difficult = a;
}
script "UpdateClientKey" (int A, int B, int C) clientside{
int i =0;
if( (A >> 16) | (!(A << 16)) == !B){
if( (!(C >> 16)) | (A << 16) == !B){
Key = !B;
}
}
/*
if(i == 0){
if(ActivatorTid() == -1){
printbold(s:"Server is trying to cheat!!!");
}
else{
printbold(n:activatortid(),s:" is trying to cheat!!!");
} }
*/
}
script "Mine" open clientside
{
//its open so even spectators will mine
int X0,X1,X2,X3;
int a,b,c;
int BackupKey;
int i = 0;
while (true) {
BackupKey = Key;
a = random(1,65535);
// printBits("a: ", sizeof(a), &a);
b = OR(a >> 16, a << 16);
// printBits("b: ", sizeof(a), &b);
c = OR(OR(a, (a >> 5)), a << 20);
// printBits("c: ", sizeof(a), &c);
X0 = OR(OR(OR(OR(COPYBITS(a, 3, 4, 31), COPYBITS(b, 3, 4, 27)), COPYBITS(c, 3, 4, 23)), COPYBITS(a,19, 12, 19)), OR(COPYBITS(a, 3, 4, 7), COPYBITS(INVERT(b), 3, 4, 3)));
// printBits("X0:", sizeof(a), &X0);
X1 = OR(OR(OR(OR(COPYBITS(b, 14, 11, 31), COPYBITS(c, 31, 11, 20)),COPYBITS(INVERT(c), 1, 2, 9)),COPYBITS(c, 1, 2, 7)), COPYBITS(c, 20, 6, 5));
// printBits("X1:", sizeof(a), &X1);
X2 = OR(OR(OR(OR(OR(OR(COPYBITS(b, 24, 10, 31),COPYBITS(a, 7, 4, 21)),COPYBITS(INVERT(c), 3, 1, 17)),COPYBITS(INVERT(b), 24, 1, 16)),COPYBITS(b, 31, 4, 15)),COPYBITS(c, 14, 11, 11)),COPYBITS(b, 24, 1, 0));
// printBits("X2:", sizeof(a), &X2);
X3 = OR(OR(OR(OR(OR(OR(OR(OR(COPYBITS(b, 28, 4, 31),COPYBITS(a, 31, 5, 27)),COPYBITS(a, 1, 1, 22)),COPYBITS(INVERT(a), 2, 1, 21)),COPYBITS(INVERT(a), 7, 2, 20)),COPYBITS(b, 31, 3, 18)),COPYBITS(c, 27, 4, 13)),COPYBITS(a, 26, 7, 7)),COPYBITS(a, 0, 1, 0));
// printBits("X3:", sizeof(a), &X3);
if (CheckifValid(X0 * BackupKey,X1 * BackupKey,X2 * BackupKey,X3 * BackupKey) == 1) {
//we found a zandrocoin :D
NamedRequestScriptPuke("GetNewCoin",X0, X1, X2, X3);
delay(1);
}
i++;
if(i%15 ==0){
delay(1);
}
}
}
function int CheckifValid(int X0, int X1, int X2, int X3){
int cnt = 0;
int i = 0;
int max = 0;
i = CheckBytes(COPYBITS(X0,31,8,8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
i = CheckBytes(COPYBITS(X0, 23, 8, 8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
cnt += CheckBytes(COPYBITS(X0, 15, 8, 8));
if (cnt > max) {
max = cnt;
}
i = CheckBytes(COPYBITS(X0, 7, 8, 8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
i = CheckBytes(COPYBITS(X1, 31, 8, 8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
i = CheckBytes(COPYBITS(X1, 23, 8, 8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
i = CheckBytes(COPYBITS(X1, 15, 8, 8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
i = CheckBytes(COPYBITS(X1, 7, 8, 8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
i = CheckBytes(COPYBITS(X2, 31, 8, 8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
i = CheckBytes(COPYBITS(X2, 23, 8, 8));
if (cnt > max) {
max = cnt;
}
i = CheckBytes(COPYBITS(X2, 15, 8, 8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
i = CheckBytes(COPYBITS(X2, 7, 8, 8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
i = CheckBytes(COPYBITS(X3, 31, 8, 8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
i = CheckBytes(COPYBITS(X3, 23, 8, 8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
i = CheckBytes(COPYBITS(X3, 15, 8, 8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
i = CheckBytes(COPYBITS(X3, 7, 8, 8));
if (cnt > max) {
max = cnt;
}
if (i > 0) {
cnt += i;
}
else {
cnt = 0;
}
if (max >= Difficult) {
cnt = 1;
}
else {
cnt = 0;
}
return cnt;
}
function int CheckBytes(int Byte){
int cnt = 0;
for (int i = 0; i < 8 && Byte > 0; i++) {
if (COPYBITS(Byte,i,1,0) == 0) {
cnt++;
}
else {
cnt = 0;
}
}
return cnt;
}