Kaillera 의 게임입력 처리방법
카일레라란?
A document describing how aes algorithm is compatible with c++ and java.
c++ side used cryptopp library which is is a free C++ class library of cryptographic schemes.
cryptopp supports AES, DES, SEED, BASE64/32 and so on.
java side used Cipher in java’s default libraries. The encrypt key of this examples is “A”*16(They are the same.)
I hope it will help you used AES in C++, java.
c++ side
#include <cryptopp/base64.h>
#include <cryptopp/aes.h>
#include <cryptopp/seed.h>
#include <cryptopp/des.h>
#include <cryptopp/modes.h>
#include <cryptopp/filters.h>
template <class TyMode>
std::string Encrypt(TyMode &Encryptor, const std::string &PlainText)
{
std::string EncodedText;
try {
CryptoPP::StringSource(PlainText, true,
new CryptoPP::StreamTransformationFilter(Encryptor,
//new CryptoPP::Base64Encoder(
new CryptoPP::StringSink(EncodedText)
//, false
//),
,CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING
)
);
}
catch (...) {}
return EncodedText;
}
template <class TyMode>
std::string Decrypt(TyMode &Decryptor, const std::string &EncodedText)
{
std::string RecoveredText;
try {
CryptoPP::StringSource(EncodedText, true,
//new CryptoPP::Base64Decoder(
new CryptoPP::StreamTransformationFilter(Decryptor,
new CryptoPP::StringSink(RecoveredText),
CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING
)
//)
);
}
catch (...) {}
return RecoveredText;
}
template <class Ty>
std::string CBC_Encrypt(uint8_t *KEY, uint8_t *IV, const std::string &PlainText)
{
typename CryptoPP::CBC_Mode<Ty>::Encryption Encryptor(KEY, Ty::DEFAULT_KEYLENGTH, IV);
return Encrypt(Encryptor, PlainText);
}
template <class Ty>
std::string CBC_Decrypt(uint8_t *KEY, uint8_t *IV, const std::string &PlainText)
{
typename CryptoPP::CBC_Mode<Ty>::Decryption Decryptor(KEY, Ty::DEFAULT_KEYLENGTH, IV);
return Decrypt(Decryptor, PlainText);
}
template <class Ty>
std::string ECB_Encrypt(uint8_t *KEY, const std::string &PlainText)
{
typename CryptoPP::ECB_Mode<Ty>::Encryption Encryptor(KEY, Ty::DEFAULT_KEYLENGTH);
return Encrypt(Encryptor, PlainText);
}
template <class Ty>
std::string ECB_Decrypt(uint8_t *KEY, const std::string &PlainText)
{
typename CryptoPP::ECB_Mode<Ty>::Decryption Decryptor(KEY, Ty::DEFAULT_KEYLENGTH);
return Decrypt(Decryptor, PlainText);
}
template <class CryptoType>
void Test()
{
using namespace std;
const std::string sText = "Plain Text";
std::string sEnc, sDec;
uint8_t KEY[CryptoType::DEFAULT_KEYLENGTH];
for(int i=0; i<CryptoType::DEFAULT_KEYLENGTH; i++) {
KEY[i] = 'A';
}
uint8_t IV[CryptoType::BLOCKSIZE] = { 0x01, };
// CBC 모드
sEnc = CBC_Encrypt<CryptoType>(KEY, IV, sText);
sDec = CBC_Decrypt<CryptoType>(KEY, IV, sEnc);
cout << CryptoType::StaticAlgorithmName() << " : " << "CBC_MODE" << endl;
//cout << sText << "\n -> " << sEnc << "\n -> " << sDec << endl;
for(int i=0; i<sEnc.size(); i++) {
printf("%x \n", sEnc[i] & 0xff);
}
cout << endl;
// ECB 모드
sEnc = ECB_Encrypt<CryptoType>(KEY, sText);
sDec = ECB_Decrypt<CryptoType>(KEY, sEnc);
cout << CryptoType::StaticAlgorithmName() << " : " << "ECB_MODE" << endl;
cout << sText << "\n -> " << sEnc << "\n -> " << sDec << endl;
cout << endl;
for(int i=0; i<sEnc.size(); i++) {
printf("%x \n", (uint8_t)sEnc[i] & 0xff);
}
}
int main()
{
using namespace std;
// AES
Test<CryptoPP::AES>();
return 0;
}
result
AES : ECB_MODE
Plain Text
-> ��
Ћ~�˹��q��Vr
-> Plain Text
fe
1b
b
d0
8b
7e
f4
cb
b9
1c
ec
71
89
85
56
72
java side
public static String encrypt(String message) throws Exception{
if(message == null){
return null;
}else{
String key = "";
for(int i=0; i<16; i++) {
key += "A";
}
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
byte[] encrypted = cipher.doFinal(message.getBytes());
return byteArrayToHex(encrypted);
}
}
private static String byteArrayToHex(byte[] encrypted) {
if(encrypted == null || encrypted.length ==0){
return null;
}
StringBuffer sb = new StringBuffer(encrypted.length * 2);
String hexNumber;
for(int x=0; x<encrypted.length; x++){
hexNumber = "0" + Integer.toHexString(0xff & encrypted[x]);
sb.append(hexNumber.substring(hexNumber.length() - 2));
}
return sb.toString();
}
try {
Log.i("gl", encrypt("Plain Text"));
} catch (Exception e) {
e.printStackTrace();
}
result
fe1b0bd08b7ef4cbb91cec7189855672
The results of both algorithms are the same.
카일레라란?
바이트 다루기
GOLANG 과 C언어
과거 펄 바람
Serverless Telegram Bot 만들기
MAME 기반의 게임 해킹
자료형 정의
언어 명세
구문분석이란
토큰화하는 방법
어릴 적 이야기 및 제작동기 어릴 적 이야기. 나는 학교에서 한 반에 있을 법한 컴퓨터를 매우 좋아하는 아이였다. 뭐 누구나 그렇겠지만 좋아하면 더 하고 싶고, 더 공부하고 싶고 그런다. 흘러 흘러 프로그래밍을 배우게 되었고 중3 겨울방학 Win32 API 에 빠져있던 무렵, 나에...
WebRTC
Action Lists
vim-surround 분석
types of perl
ap_item.xml
code-cave.zip
파일 리버싱에 있어서 RVA 와 RAW offset 을 서로간의 위치 관계를 잘 매핑해야한다.
앞서 RVA to RAW 에 대해서 알아보았다.
``` #1905 손현곤 (sonsea ) [강좌] C 포인터 선언 이해의 새장 (소개) 01/04 12:53 25 line
c++-gui-library 두서없이 적는 c++ gui library 에 대한 생각
C++ version
beast library Beast is one of the c++ network library types. beast library belongs to boost libraries(Everyone knows boost).
post method’s performance
codingame: https://www.codingame.com/ide/puzzle/2-player-game-on-a-calculator
asio tutorial1 대상 C++ 의 기본적인 문법을 이해하는데 무리가 없고 STL 에 어느정도 거부감이 없는 사람
loadRSAKey
rsa encode and decode in C++
openssl example
```cpp
https://stackoverflow.com/questions/5861722/force-boostasiobuffer-to-copy-by-value
Vim Script 를 배워봅시다.== 이 페이지는 vim 사용법을 알려주는 페이지는 아니다. 좀 더 vim 고급 사용자로 가기 위해서 vim-script 를 배우는 페이지다.
사실.
https://meetingcpp.com/blog/items/c11-and-boost.html
This is multiplication using FFT
This is simple async http request example.
Strategy Pattern
aes-java-cpp
```cpp
```cpp // // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com) // // Distributed under the Boost Software License, Version 1.0. (See a...