From 9185dc46bac4360c757270b55ed1fbf076de217e Mon Sep 17 00:00:00 2001 From: kwaroran Date: Sat, 14 Sep 2024 02:31:12 +0900 Subject: [PATCH] Remove cipherChat.ts file and related functions --- src/ts/process/cipherChat.ts | 91 ------------------------------------ 1 file changed, 91 deletions(-) delete mode 100644 src/ts/process/cipherChat.ts diff --git a/src/ts/process/cipherChat.ts b/src/ts/process/cipherChat.ts deleted file mode 100644 index ad37eaf9..00000000 --- a/src/ts/process/cipherChat.ts +++ /dev/null @@ -1,91 +0,0 @@ -import type { OpenAIChat } from "."; - - -let lastShift = 0 - -const cipher:'caesar'|'base64' = 'caesar' - -export function cipherChat(chat: OpenAIChat[]): OpenAIChat[] { - - const shift = Math.floor(Math.random() * 26) + 1 - lastShift = shift - - for(let i = 0; i < chat.length; i++){ - chat[i].content = ciphers[cipher].encode(chat[i].content, shift) - } - - chat.unshift({ - content: ciphers[cipher].prompt.replace("${shift}", shift.toString()), - role: 'system' - }) - return chat - -} - - -export function decipherChat(chat: string): string { - return ciphers[cipher].decode(chat, lastShift) -} - -//Caesar Chiper -const caesarCipher = (text: string, shift: number) => { - return text - .split('') - .map(char => { - const code = char.charCodeAt(0) - if ((code >= 65) && (code <= 90)) { - return String.fromCharCode(((code - 65 + shift) % 26) + 65) - } else if ((code >= 97) && (code <= 122)) { - return String.fromCharCode(((code - 97 + shift) % 26) + 97) - } else { - return char - } - }) - .join('') -} - -const caesarDecipher = (text: string, shift: number) => { - return text - .split('') - .map(char => { - const code = char.charCodeAt(0) - if ((code >= 65) && (code <= 90)) { - const shifted = (code - 65 - shift) - if(shifted < 0){ - return String.fromCharCode(((code - 65 - shift + 26) % 26) + 65) - } - return String.fromCharCode(((code - 65 - shift) % 26) + 65) - } else if ((code >= 97) && (code <= 122)) { - const shifted = (code - 97 - shift) - if(shifted < 0){ - return String.fromCharCode(((code - 97 - shift + 26) % 26) + 97) - } - return String.fromCharCode(((code - 97 - shift) % 26) + 97) - } else { - return char - } - }) - .join('') -} - -const base64Encode = (text: string) => { - return Buffer.from(text).toString('base64') -} - -const base64Decode = (text: string) => { - return Buffer.from(text, 'base64').toString('ascii') -} - - -const ciphers = { - caesar: { - encode: caesarCipher, - decode: caesarDecipher, - prompt: "You are an expert on The Caesar Cipher. We will communicate in Caesar Cipher. Do not be a translator. We are using shift ${shift}" - }, - base64: { - encode: base64Encode, - decode: base64Decode, - prompt: "You are an expert on The Base64 Cipher. We will communicate in Base64. Do not be a translator." - } -} \ No newline at end of file