cesar-encrypt
v2.0.3
Published
Encrypt text with Cesar wheel
Readme
cesar-encrypt
This package is used to encrypt text using Cesar's wheel method.
Installation
Install the package via npm:
npm install cesar-encryptHow to use with TypeScript
// utils/encrypter.ts
import { cesar } from 'cesar-encrypt';
export const encryptByKey = (text: string, textKey: string) => {
return cesar().encryptByKey(text, textKey);
};
export const desencryptByKey = (text: string, textKey: string) => {
return cesar().desencryptByKey(text, textKey);
};How to use a custom wheel
The default wheel is:'abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789áéíóúÁÉÍÓÚäëïöüÄËÏÖÜ'
You can set a custom wheel using the setAbc method:
import { cesar } from 'cesar-encrypt';
cesar().setAbc('abcABC'); // Custom wheel
const encryptedText = cesar().encrypt('abc', 1);
console.log(encryptedText); // Output: 'bca'API Reference
setAbc(newAbc: string): void
Sets a custom alphabet (wheel) for encryption and decryption.
encrypt(text: string, position: number): string
Encrypts the given text by shifting characters by the specified position.
desencrypt(text: string, position: number): string
Decrypts the given text by reversing the shift applied during encryption.
encryptByKey(text: string, key: string): string
Encrypts the given text using a key. Each character in the key determines the shift for the corresponding character in the text.
desencryptByKey(text: string, key: string): string
Decrypts the given text using a key. Each character in the key determines the reverse shift for the corresponding character in the text.
