Skip to content

Commit a9419c4

Browse files
committed
feat: xor encryption
1 parent c44fbf0 commit a9419c4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/App.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {petalCountLoggerInit} from "@/petalCountLogger.ts";
1515
import Api from "@/Api.vue";
1616
import '@/commands/builtin';
1717
import {gameChatUtilityInit} from "@/gameChat/gameChatUtility.ts";
18+
import XorEncryptor from "@/encryption/xor.ts";
1819
const { t } = useI18n();
1920
2021
const webSocketServerAddress = import.meta.env.VITE_SERVER;
@@ -23,6 +24,9 @@ switch (import.meta.env.VITE_ENCRYPTION) {
2324
case 'none':
2425
webSocketService.applyEncryptor(new NoneEncryptor());
2526
break;
27+
case 'xor':
28+
webSocketService.applyEncryptor(new XorEncryptor(import.meta.env.VITE_ENCRYPTION_KEY));
29+
break;
2630
}
2731
injectAPI().then(({ inventory, chatBase, chatOverflow }) => {
2832
petalCountLoggerInit(inventory);

src/encryption/xor.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {Encryptor} from "./encryption.ts";
2+
3+
export default class XorEncryptor extends Encryptor{
4+
private key: Uint8Array;
5+
constructor(key: Uint8Array) {
6+
super();
7+
this.key = key;
8+
}
9+
async decrypt(data: Uint8Array) {
10+
return data.map((byte, index) => byte ^ this.key[index % this.key.length]);
11+
}
12+
13+
async encrypt(data: Uint8Array) {
14+
return data.map((byte, index) => byte ^ this.key[index % this.key.length]);
15+
}
16+
}

0 commit comments

Comments
 (0)