Skip to content

Instantly share code, notes, and snippets.

@sebnow
Created September 10, 2010 05:11
Show Gist options
  • Save sebnow/573138 to your computer and use it in GitHub Desktop.
Save sebnow/573138 to your computer and use it in GitHub Desktop.
Onet Czat AUTH Key decryption
/* Copyright (c) 2010 Sebastian Nowicki <sebnow@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int ocauth_authkey(char *challenge, char *response) {
static const int f1[] = {
29, 43, 7, 5, 52, 58, 30, 59, 26, 35, 35, 49, 45, 4, 22, 4, 0,
7, 4, 30, 51, 39, 16, 6, 32, 13, 40, 44, 14, 58, 27, 41, 52, 33,
9, 30, 30, 52, 16, 45, 43, 18, 27, 52, 40, 52, 10, 8, 10, 14,
10, 38, 27, 54, 48, 58, 17, 34, 6, 29, 53, 39, 31, 35, 60, 44,
26, 34, 33, 31, 10, 36, 51, 44, 39, 53, 5, 56
};
static const int f2[] = {
7, 32, 25, 39, 22, 26, 32, 27, 17, 50, 22, 19, 36, 22, 40, 11,
41, 10, 10, 2, 10, 8, 44, 40, 51, 7, 8, 39, 34, 52, 52, 4, 56,
61, 59, 26, 22, 15, 17, 9, 47, 38, 45, 10, 0, 12, 9, 20, 51, 59,
32, 58, 19, 28, 11, 40, 8, 28, 6, 0, 13, 47, 34, 60, 4, 56, 21,
60, 59, 16, 38, 52, 61, 44, 8, 35, 4, 11
};
static const int f3[] = {
60, 30, 12, 34, 33, 7, 15, 29, 16, 20, 46, 25, 8, 31, 4, 48, 6,
44, 57, 16, 12, 58, 48, 59, 21, 32, 2, 18, 51, 8, 50, 29, 58, 6,
24, 34, 11, 23, 57, 43, 59, 50, 10, 56, 27, 32, 12, 59, 16, 4,
40, 39, 26, 10, 49, 56, 51, 60, 21, 37, 12, 56, 39, 15, 53, 11,
33, 43, 52, 37, 30, 25, 19, 55, 7, 34, 48, 36
};
static const int p1[] = {
11, 9, 12, 0, 1, 4, 10, 13, 3, 6, 7, 8, 15, 5, 2, 14
};
static const int p2[] = {
1, 13, 5, 8, 7, 10, 0, 15, 12, 3, 14, 11, 2, 9, 6, 4
};
char ai[16], ai1[16], c;
int i;
for(i = 0; i < 16; i++) {
c = challenge[i];
ai[i] = (c > '9' ? c > 'Z' ? (c - 97) + 36 : (c - 65) + 10 : c - 48);
}
for(i = 0; i < 16; i++) {
ai[i] = f1[ai[i] + i];
}
memcpy(ai1, ai, sizeof(ai1));
for(i = 0; i < 16; i++) {
ai[i] = (ai[i] + ai1[p1[i]]) % 62;
}
for(i = 0; i < 16; i++) {
ai[i] = f2[ai[i] + i];
}
memcpy(ai1, ai, sizeof(ai1));
for(i = 0; i < 16; i++) {
ai[i] = (ai[i] + ai1[p2[i]]) % 62;
}
for(i = 0; i < 16; i++) {
ai[i] = f3[ai[i] + i];
}
for(i = 0; i < 16; i++) {
c = ai[i];
ai[i] = c >= 10 ? c >= 36 ? (97 + c) - 36 : (65 + c) - 10 : 48 + c;
}
memcpy(response, ai, sizeof(ai));
response[sizeof(ai)] = '\0';
return 1;
}
/* Copyright (c) 2010 Sebastian Nowicki <sebnow@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/* Function ocauth_authkey
Decodes Onet Czat AUTHKEY challenge.
This is required for authorization with the Onet Czat IRC server.
Authorization looks like this:
:<HOST> 801 604-unknown :b5K1YELHITAT76ZY
AUTHKEY GY4wF74R6N4uPtxy
The first value is the challenge, the second value is the response.
Parameters:
challenge - The challenge retrieved from an Onet Czat IRC server.
response - Pointer to the object where the response should be stored.
Returns:
1 on success, 0 on error.
References:
Algorithm is based on the Onet Czat Java applet sources and the
algorithm provided by frasunek:
http://www.frasunek.com/old/onet.html
*/
int ocauth_authkey(char *challenge, char *response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment