mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
merge: Add Affine Cipher (#1067)
* Add Affine Cipher * Replace IndexOf function to improve performance * remove leading spacing and fixed typo * Remove leading spacing in first row.
This commit is contained in:
27
Ciphers/test/AffineCipher.test.js
Normal file
27
Ciphers/test/AffineCipher.test.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import { encrypt, decrypt } from '../AffineCipher'
|
||||
|
||||
describe('Test Affine Cipher', () => {
|
||||
it('Test - 1, Pass invalid input to encrypt function', () => {
|
||||
expect(() => encrypt(null, null, null)).toThrow()
|
||||
expect(() => encrypt('null', null, null)).toThrow()
|
||||
expect(() => encrypt('null', 1, null)).toThrow()
|
||||
expect(() => encrypt('null', null, 1)).toThrow()
|
||||
})
|
||||
|
||||
it('Test - 2, Pass invalid input to decrypt function', () => {
|
||||
expect(() => decrypt(null, null, null)).toThrow()
|
||||
expect(() => decrypt('null', null, null)).toThrow()
|
||||
expect(() => decrypt('null', 1, null)).toThrow()
|
||||
expect(() => decrypt('null', null, 1)).toThrow()
|
||||
})
|
||||
|
||||
it('Test - 3 Pass string value to encrypt and ecrypt function', () => {
|
||||
const a = 5
|
||||
const b = 8
|
||||
expect(decrypt(encrypt('HELLO WORLD', a, b), a, b)).toBe('HELLO WORLD')
|
||||
expect(decrypt(encrypt('ABC DEF', a, b), a, b)).toBe('ABC DEF')
|
||||
expect(decrypt(encrypt('Brown fox jump over the fence', a, b), a, b)).toBe(
|
||||
'BROWN FOX JUMP OVER THE FENCE'
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user