In hindsight, trying to add comments into that code made it look really sloppy.
Fixed:
I'm trying to implement tripcodes in my imageboard software, but I've run into some problems.
The following Ruby pseudo-code handles tripcodes(if you don't know Ruby, this should still be farily readable):
if author_name =~ /^[^#]*#.*/
trip = author_name.match(/[^#]*#(.*)/)[1].to_s
author_name = author_name.match(/([^#]*)#.*/)[1])
author_tripcode = trip.crypt(trip[1,2])[3..12])
end
Basically, if the inputted name is 0 or more non-hash characters followed by a hash and then followed by 0 or more characters, separate what's before the hash from what's after the hash, call crypt on what was after the hash, take the 2nd/3rd characters and use them as salt, and take the last 10 characters from the result for tripcode justice.
This has a few flaws. One, it cannot handle a blank tripcode. Since it gets salt from the second/third letters, if these letters don't exist, it is a failure. I don't know what to use if the tripcode is under 3 characters. I noticed that in Wakaba I can enter just "#" in the Name field and get a result.
Secondly, as WAHa told me, there are varyious methods on how to handle special characters in tripcodes (ie no 100% agreement between scripts). I don't know any of them. Furthermore I cannot decipher Wakaba or Futallaby to make sense out of how those scripts do it.
to get the salt, take the first three characters of the tripcode (or the whole thing if it's shorter than three characters), append "H.." onto the end and then use the second and third characters of the resulting string as the salt.
>>4 is kind of right, but it's clearer to state it this way:
To get the salt, take the trip string, append "H..", and then take the second and third characters.
If I recall correctly, you should do the equivalent of the PHP function htmlspecialchars() on the tripcode before processing it. At least I think Futaba does this - I forget what 0ch does.
And finally, if you want to be really correct, and want the original # tripcode to work, you need to convert from whatever character set you happen to be using on the page (possibly including converting numerical HTML entities) to Shift_JIS encoding.
Gah, what the hell, did Camino break from a couple of fullwidth characters?
That's supposed to be "#kami", but written with the japanese fullwidth characters as opposed to the Basic Latin ones.
>>5
Okay, there is htmlspecialchars() which turns special characters into HTML entities, for example "&" becomes "&", and there's htmlspecialchars_decode() which does the reverse. So which direction should I be going? Just want to double-check because you didn't seem to be entirely sure on htmlspecialchars()
I also have no idea what Shift_JIS encoding is. I've heard it several times and never bothered to look it up, so I guess I will have to do that now.
>If I recall correctly, you should do the equivalent of the PHP function htmlspecialchars() on the tripcode before processing it. At least I think Futaba does this - I forget what 0ch does.
Looking at Futallaby, I see this (I've modified it so it makes more sense):
$tripcode=strtr($tripcode,"&", "&");
$tripcode=strtr($tripcode,",", ",");
strtr() takes a string and replaces "&" with "&", and so on, so I guess that what you meant is htmlspecialchars_decode() which would turn special characters into their non-HTML forms. Either that or futallaby does it wrong. (Also, the creator was either unaware of htmlspecialchars_decode() or it wasn't part of PHP when he was writing the script.)
I then tried the tripcode "#&&&" in my app, and then in Wakaba. There was a difference in tripcodes. I continued to fool around and eventually tried inputting "#&&&" in my app's name field and matched Wakaba's output.
So Wakaba uses the HTML entities when encoding, and Futallaby doesn't? Which way is "right" or which method is closer to older imageboard scripts? I feel that it makes more sense that the special characters remain as they are.
Does PHP usually convert special characters to HTML entities before storing them in the database, which is why the conversion is necessary? I did not have to do any conversion in my case.
I'm confused.
What both told me was very helpful, though.
Futallaby is wrong. 0ch-PHP or Shiichan or Wakaba are right, though.
The actual behavior is probably a bug in 0ch, which is why it seems obviously wrong, but since 0ch is the canon it's what should be imitated.
Honestly, I don't recall if I am doing it right or not.
If you want to go to the source, you should be testing on 2ch.net. Grab an unpopular thread on News4VIP (http://ex15.2ch.net/news4vip/) and post your saged tests there. Threads cycle through there in less than a day, anyway.
Okay the "& # 4 4 ;" I typed out got turned into an actual comma, cool.
Okay my app's results are identical to what I get on 2ch.net
So I'm still confused on what's actually taking place, but I'm not going to worry myself about it since it works as intended I won't worry myself with it.
Which counts as the "tripcode", the encoded or unencoded string?
> Which counts as the "tripcode", the encoded or unencoded string?
Some days, I am completely unable to write code because I can't figure this out and thus can't give my variables the right names.
>>16
Lol, I don't know if this is sarcasm or what.
On an unrelated note, I hate when I read my previous posts and find huge typos and grammatical errors.
Me neither.
>>18
Usually I just go with the best name I can think of at the time, and worry about it later. Which is why I have to do a lot of manual refactoring, because I'm so indecisive.
But I guess a tripcode unencrypted is a tripcode encrypted. I mean, even if a password isn't stored in a database as plaintext, it's still the password, no one really has different names for a plaintext/encrypted password. So.
www.paheal.net
Thanks, but since I've given up development on my imageboard, it's pretty useless. As is my imageboard, which wasn't very far from being very functional. Too bad nobody knows Ruby on Rails.
Can you post the source to your tripcode function please?
def entrip(key)
if key.blank? then return "" end
key = CGI.escapeHTML(key)
key += "H.."
salt = key[1,2]
return key.crypt(salt)[3..12]
end
Mine doesn't match what 2ch has :(
>>23
Well, no wonder. Right idea, but quite wrong implementation :)
I have no idea how Ruby does these things, but from my very brief workings with it, it seems similar enough to Perl that this might be useful:
# encode as shift-jis before doing anything
# (note: this implies that the salt value is potentially
# using HALVES of full-width characters!)
$key = encode "sjis", decode "utf8", $key;
# salt is the second and third character of the key
# note that the H.. is not added to the key itself,
# this is only done when getting the salt value
$salt = substr($key . "H..", 1, 2);
# change this -> : ; < = > ? @ [ \ ] ^ _ `
# into this -> A B C D E F G a b c d e f
$salt =~ tr!\x3A-\x40\x5B-\x60!A-Ga-f!;
# anything else except alphanumeric, dot, and slash
# should be changed into a dot
$salt =~ tr!0-9A-Za-z./!.!c;
$trip = substr(crypt($key, $salt), 3);
The two transforms on the salt are really important, else pretty much any tripcode that's not just letters and numbers will be wrong.
Every board seems to do some things slightly differently (e.g. whether to escape html characters or not; what characters to escape; etc.) but that's pretty much the basic implementation.
right if the code is bobh523 = #292hdns or whatever (this is not the code) what do i enter into the name field to get to to display my name as bob?
This is not a real code, just cant figure out how to make this shit work.
fuck
mehh
qwe