From e4a27aee2e1bf3e808091ec0119e71c5353772e7 Mon Sep 17 00:00:00 2001 From: "Samuel Egbajie (MAJ0R)" <49847624+CodePapi@users.noreply.github.com> Date: Thu, 8 Sep 2022 15:43:07 +0200 Subject: [PATCH] added readme --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/app.ts | 16 +++++++++------- src/index.ts | 9 +-------- 3 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..48c03a9 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +## How to use this package crypta + +This package allows you to encrypt and decrypt short strings using a key. It is based on the [AES](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard) algorithm. + +### Installation + +```bash +npm install crypta +``` + +### Usage + +```javascript +const crypta = require('crypta'); + +const key = 'my secret key'; +const text = 'my secret text'; + +const encrypted = crypta.encrypt(text, key); +const decrypted = crypta.decrypt(encrypted, key); + +\`\`\` + +### API + +#### encrypt(text, key) + +Encrypts the given text using the given key. + +#### decrypt(encrypted, key) + +Decrypts the given encrypted text using the given key. + +### License + +MIT + +## How to use this package crypta + +This package allows you to encrypt and decrypt short strings using a key. It is based on the [AES](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard) algorithm. + +### Installation + +```bash +npm install crypta +``` + diff --git a/src/app.ts b/src/app.ts index 4058c47..5da2513 100644 --- a/src/app.ts +++ b/src/app.ts @@ -7,7 +7,7 @@ const hash = (str:string) => const offset = (num:number, i:number) => parseInt(num.toString().charAt(i % num.toString().length)); -export const encryptPassword = (st:string, sa:string, d = 1) =>{ +export const encrypt = (st:string, sa:string, d = 1) =>{ const hashSalt:number=hash(sa) return st .split("") @@ -15,14 +15,16 @@ export const encryptPassword = (st:string, sa:string, d = 1) =>{ .join(""); } -export const decryptPassword = (str:string, salt:string) => { - return encryptPassword(str, salt, -1);} +export const decrypt = (str:string, salt:string) => { + return encrypt(str, salt, -1);} const salt = "test"; const str = "My name is john bosco"; -const scram = encryptPassword(str, salt); -const unscram = decryptPassword(scram, salt); +const scram = encrypt(str, salt); +const unscram = decrypt(scram, salt); -console.log("encryptPassword:", scram); -console.log("decryptPassword:", unscram); \ No newline at end of file +console.log("encrypt:", scram); +console.log("decrypt:", unscram); + +export default { encrypt, decrypt }; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index ae82ca9..aa01a4f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1 @@ -import {encryptPassword, decryptPassword} from "./app" -export {encryptPassword, decryptPassword} from "./app" - -console.log("test") - -console.log(encryptPassword("My name is john bosco","test")) -console.log(encryptPassword("My name is john bosco","test",-1)) -console.log(decryptPassword("My name is john bosco","test")) \ No newline at end of file +export { encrypt, decrypt } from './app';