-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
executable file
·163 lines (147 loc) · 6.58 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE HTML>
<html>
<head>
<!-- This is our function array -->
<script src ="functions.js"> </script>
<script src ="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<!-- These are our general utility functions -->
<script>
//Utility Functions
//Converts the first character of a string into its ascii int representation
function ord(String){
return String.charCodeAt(0);
}
//Converts an int into its ascii character
function chr(asciiint){
return String.fromCharCode(asciiint);
}
//Displays remaining characters under textarea
function LimitText(AId, BId){
var e1 = document.getElementById(AId);
var e2 = document.getElementById(BId);
var l1 = e1.value.length;
(l1 > 130) ? e1.value = e1.value.substring(0, 130) : e2.innerHTML = 130 - l1
}
function checkText(elementID) {
var text = document.getElementById(elementID).value;
var subtext = text.charAt(text.length-1);
if (ord(subtext) < 32 || ord(subtext) > 126) {
document.getElementById(elementID).value = text.substring(0,text.length-1);
}
}
function notEmpty() {
var message = document.getElementById("mtext").value;
var hashtag = document.getElementById("hashtag").value;
if (message.length == 0 || hashtag.length == 0){
document.getElementById("errortext").innerHTML = "Please fill in both the message and the passkey.";
}
else document.getElementById("errortext").innerHTML = "";
}
//Converts string into an array of individual character ascii codes
function arrayze(String){
var theArray = String.split(""); //this splits every character
for (var i = 0; i < theArray.length; i++) {
theArray[i] = ord(theArray[i]);
}
return theArray;
}
//Converts hashtag into ascii ints and adds together for a checksum-style offset
function getHashtag(){
var hashTag = document.getElementById("hashtag").value;
hashTag = arrayze(hashTag);
// var value = 0;
// for (var i = 0; i< hashTag.length; i++){
// value = value +hashTag[i];
// }
return hashTag;
}
//Takes ascii int values in an array and encrypts them using a function chosen from our list
function munge(mungeArray, offset){
for (var i = 0; i < mungeArray.length; i++) {
var encryptFunction = encryptr[offset[i%offset.length]]; //% mungeArray.length];//Selecting a function from our list
mungeArray[i] = encryptFunction(mungeArray[i]) % 96 + 32;//Perform
//console.log(mungeArray[i]);
}
return mungeArray;
}
function unMunge(mungeArray, offset){
for (var i = 0; i < mungeArray.length; i++) {
mungeArray[i] -= 32;
var decryptFunction = decryptr[offset[i%offset.length]];//Selecting a function from our list
if (decryptFunction(mungeArray[i]) < 32) {
mungeArray[i] = decryptFunction(mungeArray[i]) + 96;
if (mungeArray[i] < 32) mungeArray[i] += 96;
}
else
mungeArray[i] = decryptFunction(mungeArray[i]);
//console.log(mungeArray[i]);
}
return mungeArray;
}
function reString(theArray){
for (var i = 0; i < theArray.length; i++) {
theArray[i] = chr(theArray[i]);
}
var finished = theArray.join("");
return finished;
}
function getRequest(theURL,theData,theTweet){
$.ajax(
{
url: theURL,
data: theData,
type: 'GET',
dataType: 'html',
timeout: 1000,
error: function(){
alert('Unable to connect to authentication server');
},
success: function(theText)
{
encodedHash = theText;
var finalTweet = theTweet + "#" + theText;
return finalTweet;
}
});
}
//Main Function
function getMessageText(){
var message = document.getElementById("mtext").value; //grab message text
message = arrayze(message); //convert each character into ascii code and save result in array
var offset = getHashtag(); //grabs offset from hastag
var munged = munge(message, offset); //munges the array of characters based on function list and offset
var tweetReady = reString(munged);
document.getElementById("mtext").value = tweetReady;
var finalTweet = getRequest("validator.php",{h:document.getElementById("hashtag").value,c:1},tweetReady);
}
function returnMessageText(){
var message = document.getElementById("mtext").value; //grab message text
message = arrayze(message); //convert each character into ascii code and save result in array
var offset = getHashtag(); //grabs offset from hastag
var unMunged = unMunge(message, offset); //munges the array of characters based on function list and offset
var tweetReady = reString(unMunged);
document.getElementById("mtext").value = tweetReady;
var finalTweet = getRequest("validator.php",{h:encodedHash,c:0},tweetReady);
}
</script>
</head>
<body>
<div id="errortext"></div>
<form action = "javascript: getMessageText(); notEmpty();">
<label>
Type text below
</label>
<input type= "text" maxlength= 8 id = "hashtag" onkeyup = "checkText('hashtag');">
<textarea id="mtext" onkeyup="LimitText('mtext','cleft'); checkText('mtext');" onblur="" rows=5 cols=30></textarea>
<br>
<label id="cleft" style="color:red;font-weight:bold">
130
</label>
<label style="color:red;font-weight:bold">
Characters Left
</label>
<input type="submit" value="Submit" />
</form>
<button onclick = "javascript: returnMessageText(); notEmpty();">Unmunge</button>
</body>
</html>