-
-
Save itsmikita/792ec5ede0abae45ed96 to your computer and use it in GitHub Desktop.
Console (Anonymous) Chat with encryption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This script requires jQuery to be included. | |
* TODO: Fix non-jQuery or insert jQuery. | |
* | |
* It also encrypts messages with your key so that only | |
* you and people you shared the key via other medias like | |
* Facebook or phone can read the messages. | |
*/ | |
// Help (: | |
function h() { | |
console.log( "C H A T H E L P" ); | |
console.log( "l( <username>, <key> ) --- Login into chat with your own secret key, only people who have this key will receive the messages (and also only ones to read it)" ); | |
console.log( "m( <message> ) --- Post a message" ); | |
console.log( "x() --- Log out, exit the chat (NOTE: clears the log)." ); | |
console.log( "h() — Prints this help menu." ); | |
} | |
// Login | |
function l( username, key ) { | |
window.__u = name; | |
window.__k = key; | |
window.__c = setInterval( function() { | |
u(); | |
}, 5000 ); | |
} | |
// Update | |
function u() { | |
$.ajax( { | |
url: ‘/ajax.php’, | |
data: { | |
t: window.__t; | |
}, | |
type: ‘POST’, | |
success: function( response ) { | |
r( response ); | |
}, | |
} ); | |
} | |
// Message | |
function m( text ) { | |
$.ajax( { | |
url: ‘/ajax.php’, | |
data: { | |
m: e( text ), | |
t: window.__t, | |
}, | |
type: ‘POST’, | |
success: function( response ) { | |
r( response ); | |
}, | |
} ); | |
}; | |
// Encypt | |
function e( text ) { | |
text = window.btoa( window.btoa( window.__k ) + window.btoa( text ) ); | |
return text; | |
} | |
// Decrypt | |
function d( text ) { | |
text = window.atob( window.atob( text ).replace( window.btoa( window.__k ), '' ) ) ); | |
return text; | |
} | |
// Response | |
function r( response ) { | |
if( ! response.messages.length ) | |
return; | |
for( var i in response.messages ) | |
console.log( response.messages[ i ].username + ‘: ‘ + d( response.messages[ i ].message ) ); | |
window.__t = this.response.time; | |
}; | |
// Exit | |
function x() { | |
claerInterval( window.__c ); | |
window.__n = null; | |
window.__k = null; | |
console.log( 'You left. Clearing log in 3 seconds...' ); | |
// Clear console log | |
setTimeout( function() { | |
console.clear(); | |
}, 3000 ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This script requires a MySQL database connection | |
* with the mapped table set properly. See database | |
* table structure. | |
*/ | |
// Instance a DB connection here | |
$db = ''; | |
// Unix timestamp it is | |
$time = intval( $_POST['t'] ); | |
// Do escape the data !!! | |
$username = $db->escape( $_POST['u'] ); | |
// If there's something to post | |
if( $_POST['m'] ) { | |
$message = $db->escape( $_POST['m'] ); | |
$db->query( "INSERT INTO c ( user, time, message ) VALUES ( '$user', '$time', '$message' );" ); | |
} | |
$messages = $db->get_results( "SELECT user, time, message FROM c WHERE time >= '$time';" ); | |
$time = time(); | |
print( json_encode( compact( 'messages', 'time' ) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `c` ( | |
`user` varchar(255) DEFAULT NULL, | |
`message` int(255) DEFAULT NULL, | |
`time` int(11) DEFAULT NULL | |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi. a quick question i need answer on. this "Console (Anonymous) Chat with encryption" .. is it a real chatsite for this? and if so.. whats the chatsite name for it?