rhash
Version:
rHash | Data Encryption | by Swôth#9990
56 lines (48 loc) • 3.52 kB
JavaScript
const swothReplacer = require('./src/swothReplacer.js');
const swothUnhash = require('./src/swothUnhash.js');
const swothHash = require('./src/swothHash.js');
const swothGen = require('./src/swothGen.js');
class rHash {
static key(length) {
if (!length) throw new Error('\n\n> (EN) rHash Error: Enter the length of the key to be created!\n> (TR) rHash Hata: Oluşturulacak anahtarın uzunluğunu yazınız!\n')
if (isNaN(length)) throw new Error('\n\n> (EN) rHash Error: Please write a valid number!\n> (TR) rHash Hata: Lütfen geçerli bir sayı yazınız!\n')
if (length < 20 || length > 1000) throw new Error('\n\n> (EN) rHash Error: For security reasons, the key length can be minimum 20 and maximum 1000!\n> (TR) rHash Hata: Güvenlik sebebi ile anahtar uzunluğu en az 20, en fazla 1000 olabilir!\n')
return swothGen(length);
}
static hash(data, key) {
if (!data) throw new Error('\n\n> (EN) rHash Error: Please enter the data to be encrypted. (Example: Hi!)\n> (TR) rHash Hata: Lütfen şifrelenecek olan veriyi giriniz. (Örnek: Selam!)\n');
if (!key) throw new Error('\n\n> (EN) rHash Error: Enter a key that will be needed later to decrypt the data!\n> (TR) rHash Hata: Bir anahtar giriniz bu anahtar daha sonra veriyi çözmek için lazım olacak!\n');
const swothHasher = swothHash(key.replace(/[^\x00-\x7F]/g,''));
const swothData = data
.split("ğ").join("|*g*|").split("Ğ").join("|*G*|").split("ç").join("|*c*|")
.split("Ç").join("|*C*|").split("ş").join("|*s*|").split("Ş").join("|*S*|")
.split("ü").join("|*u*|").split("Ü").join("|*U*|").split("ö").join("|*o*|")
.split("Ö").join("|*O*|").split("ı").join("|*i*|").split("İ").join("|*I*|");
const swothHashed = swothHasher(swothData).toUpperCase()
.split("1").join(swothReplacer("1")).split("2").join(swothReplacer("2"))
.split("3").join(swothReplacer("3")).split("4").join(swothReplacer("4"))
.split("5").join(swothReplacer("5")).split("6").join(swothReplacer("6"))
.split("7").join(swothReplacer("7")).split("8").join(swothReplacer("8"))
.split("9").join(swothReplacer("9")).split("0").join(swothReplacer("0"))
return swothHashed;
}
static unhash(code, key) {
if (!code) throw new Error('\n\n> (EN) rHash Error: Please write the code to be decrypt!\n> (TR) rHash Hata: Lütfen şifresi çözülecek kodu yazınız!\n');
if (!key) throw new Error('\n\n> (EN) rHash Error: Type in the key indicating the dissolving format!\n> (TR) rHash Hata: Çözülme biçimini belirten anahtarı yazınız!\n');
const swothCode = code.toLowerCase()
.split(swothReplacer("1")).join("1").split(swothReplacer("2")).join("2")
.split(swothReplacer("3")).join("3").split(swothReplacer("4")).join("4")
.split(swothReplacer("5")).join("5").split(swothReplacer("6")).join("6")
.split(swothReplacer("7")).join("7").split(swothReplacer("8")).join("8")
.split(swothReplacer("9")).join("9").split(swothReplacer("0")).join("0")
const swothUnhasher = swothUnhash(key.replace(/[^\x00-\x7F]/g,''));
const swothUnhashed = swothUnhasher(swothCode)
.split("|*g*|").join("ğ").split("|*G*|").join("Ğ").split("|*c*|").join("ç")
.split("|*C*|").join("Ç").split("|*s*|").join("ş").split("|*S*|").join("Ş")
.split("|*u*|").join("ü").split("|*U*|").join("Ü").split("|*o*|").join("ö")
.split("|*O*|").join("Ö").split("|*i*|").join("ı").split("|*I*|").join("İ");
return swothUnhashed;
}
}
module.exports = rHash;
module.exports.version = require('./package.json').version