KareemTalhaa
New Member
- Joined
- Sep 9, 2023
- Messages
- 12
- Reaction score
- 3
Hello everyone, I have an problem with compiling tfs 1.2 If someone can help me
RSA.CPP V
Rsa.h V
If there missing libraries tell me I don't know what should i do
![1719327547139.png 1719327547139.png](https://static3.otland.net/d/attachments/77/77252-c19c9c7333e454a9b2c9f2b27d54c39e.jpg)
RSA.CPP V
Lua:
#include "rsa.h"
#include <gmp.h>
#include <cstring>
RSA::RSA() {
mpz_init(n);
mpz_init(d);
}
RSA::~RSA() {
mpz_clear(n);
mpz_clear(d);
}
void RSA::setKey(const char* pString, const char* qString) {
mpz_t p, q, phi, e;
mpz_init_set_str(p, pString, 10);
mpz_init_set_str(q, qString, 10);
mpz_init(phi);
mpz_init(e);
// n = p * q
mpz_mul(n, p, q);
// phi = (p - 1) * (q - 1)
mpz_sub_ui(p, p, 1);
mpz_sub_ui(q, q, 1);
mpz_mul(phi, p, q);
// set e (common choice for e is 65537)
mpz_set_ui(e, 65537);
// d = e^-1 mod phi
mpz_invert(d, e, phi);
mpz_clear(p);
mpz_clear(q);
mpz_clear(phi);
mpz_clear(e);
}
void RSA::decrypt(char* msg) const {
mpz_t c, m;
mpz_init_set_str(c, msg, 16); // assuming the ciphertext is in hex format
mpz_init(m);
// m = c^d mod n
mpz_powm(m, c, d, n);
// convert the decrypted message back to a string
mpz_get_str(msg, 16, m);
mpz_clear(c);
mpz_clear(m);
}
Lua:
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2016 Mark Samman <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef FS_RSA_H_C4E277DA8E884B578DDBF0566F504E91
#define FS_RSA_H_C4E277DA8E884B578DDBF0566F504E91
#include <gmp.h>
class RSA
{
public:
RSA();
~RSA();
// non-copyable
RSA(const RSA&) = delete;
RSA& operator=(const RSA&) = delete;
void setKey(const char* pString, const char* qString);
void decrypt(char* msg) const;
private:
// use only GMP
mpz_t n, d;
};
#endif // FS_RSA_H_C4E277DA8E884B578DDBF0566F504E91
![1719327547139.png 1719327547139.png](https://static3.otland.net/d/attachments/77/77252-c19c9c7333e454a9b2c9f2b27d54c39e.jpg)
Last edited: