Skip to content

Instantly share code, notes, and snippets.

@zekesonxx
Last active August 29, 2015 13:57
Show Gist options
  • Save zekesonxx/9904781 to your computer and use it in GitHub Desktop.
Save zekesonxx/9904781 to your computer and use it in GitHub Desktop.
A really stupid ASCII rotation method that was advertized as encryption.
Public Function EncryptDecrypt(ByVal text1 As String, ByVal key As String, ByVal isEncrypt As Boolean) As String
Dim char1 As String
Dim char2 As String
Dim cKey As Byte
Dim strLength As Integer
Dim Result As String = ""
Dim j As Integer = -1
If text1 <> "" And IsNumeric(key) Then
strLength = text1.Length
For i As Integer = 0 To strLength - 1
char1 = text1.Substring(i, 1)
If j < key.Length - 1 Then
j = j + 1
Else
j = 0
End If
cKey = Val(key.Substring(j, 1))
If isEncrypt Then
If (Asc(char1) + cKey) > 255 Then
char2 = Chr(Asc(char1) + cKey - 255)
Else
char2 = Chr(Asc(char1) + cKey)
End If
Else
If (Asc(char1) - cKey) < 1 Then
char2 = Chr(Asc(char1) - cKey + 255)
Else
char2 = Chr(Asc(char1) - cKey)
End If
End If
Result &= char2
Next
Else
MsgBox("Enter text or key!")
End If
Return Result
End Function
/* jshint undef: true, node: true, quotmark: single, indent: 2 */
'use strict';
/**
* A really shitty ASCII rotation method
* Ported to JavaScript because I was throughly bored
* https://gist.github.com/zekesonxx/9904781
*
* Copyright (C) Zeke Sonxx 2014.
* Licensed under the MIT License <choosealicense.com/licenses/mit/>
* @author Zeke Sonxx <github.com/zekesonxx>
* @version 1.0.1
*/
var shitrot = module.exports = {
__doit : function (input, origkey, encrypt) {
origkey = origkey.toString();
var out = '', offset, j = -1;
for (var i=0; i<=input.length-1 ;i++) {
//Fix j because this algo is stupid
j = j < origkey.length-1 ? j + 1 : 0;
var key = parseInt(origkey.substr(j, 1));
var charcode = input.substr(i, 1).charCodeAt(0);
if (encrypt) {
offset = charcode + key > 255 ? key-255 : key;
out += String.fromCharCode(charcode+offset);
} else {
offset = charcode - key < 1 ? key+255 : key;
out += String.fromCharCode(charcode-offset);
}
}
return out;
},
/**
* Encrypts the input according to the idiotic rot method
* @param {String} input Thing to "encrypt"
* @param {Number} key Offset to rotate on
* @return {String} "encrypted" value
*/
encrypt : function (input, key) {
return this.__doit(input, key, true);
},
/**
* Decrypts the input according to the idiotic rot method
* @param {String} input Thing to "decrypt"
* @param {Number} key Offset to rotate on
* @return {String} Plaintext value
*/
decrypt : function (input, key) {
return this.__doit(input, key, false);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment