Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```

16 changes: 9 additions & 7 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ 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("")
.map((c, i) => String.fromCharCode(c.charCodeAt(0) + offset(hashSalt, i) * d))
.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);
console.log("encrypt:", scram);
console.log("decrypt:", unscram);

export default { encrypt, decrypt };
9 changes: 1 addition & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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"))
export { encrypt, decrypt } from './app';