Skip to content

Instantly share code, notes, and snippets.

@austbot austbot/service.ts
Created Feb 19, 2018

Embed
What would you like to do?
import { Injectable, Inject } from '@angular/core';
@Injectable()
export class SecretService {
constructor( @Inject('ENcRYPTI0n_k3y') private key: string) {}
//public api
encode(secret: string) {
return SecretService._encodeSecret(this.key, secret);
}
//private api
static _mapToKeyChar(key: string, char: str, index: number) {
const len = key.length;
const dist = index > len-1 ? index - len : len - index;
return key[dist];
}
static _encodeSecret(key: string, secret: string) {
return secret
.split('')
.reverse()
.map((char, index, str) => {
return SecretService._mapToKeyChar(key, char, index);
})
.join('');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.