Tripcodes, plz halp (28)

1 Post deleted by user.

2 Name: EleoChan!EhVtXXdTd6 : 2006-06-21 12:46 ID:BQCHyGN7 [Del]

In hindsight, trying to add comments into that code made it look really sloppy.

3 Name: EleoChan!EhVtXXdTd6 : 2006-06-21 12:50 ID:BQCHyGN7 [Del]

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.

4 Name: Anonymous : 2006-06-21 13:57 ID:4ui5Mx68 [Del]

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.

5 Name: !WAHa.06x36 : 2006-06-21 16:05 ID:yNXTW94z [Del]

>>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.

6 Name: !WAHa.06x36 : 2006-06-21 16:07 ID:yNXTW94z [Del]

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.

7 Name: EleoChan!EhVtXXdTd6 : 2006-06-21 16:26 ID:BQCHyGN7 [Del]

>>5
Okay, there is htmlspecialchars() which turns special characters into HTML entities, for example "&" becomes "&amp", 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.

8 Name: EleoChan!EhVtXXdTd6 : 2006-06-21 17:16 ID:BQCHyGN7 [Del]

>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.

9 Name: Mr VacBob!JqK7T7zan. : 2006-06-21 17:34 ID:GhO9ID+A [Del]

Futallaby is wrong. 0ch-PHP or Shiichan or Wakaba are right, though.

10 Name: Mr VacBob!JqK7T7zan. : 2006-06-21 17:35 ID:GhO9ID+A [Del]

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.

11 Name: !WAHa.06x36 : 2006-06-21 17:38 ID:yNXTW94z [Del]

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.

12 Post deleted by user.

13 Name: EleoChan!EhVtXXdTd6 : 2006-06-21 17:44 ID:BQCHyGN7 [Del]

Okay the "& # 4 4 ;" I typed out got turned into an actual comma, cool.

14 Post deleted by user.

15 Name: EleoChan!EhVtXXdTd6 : 2006-06-21 17:57 ID:BQCHyGN7 [Del]

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?

16 Name: !WAHa.06x36 : 2006-06-22 07:19 ID:Heaven [Del]

> 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.

17 Name: EleoChan!EhVtXXdTd6 : 2006-06-22 08:39 ID:Heaven [Del]

>>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.

18 Name: !WAHa.06x36 : 2006-06-23 07:40 ID:Heaven [Del]

>>17

Me neither.

19 Name: EleoChan!EhVtXXdTd6 : 2006-06-24 22:45 ID:Heaven [Del]

>>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.

20 Post deleted by moderator.

21 Name: Anonymous : 2006-10-25 04:27 ID:HloRCSu+ [Del]

www.paheal.net

22 Name: EleoChan!EhVtXXdTd6 : 2006-10-27 23:14 ID:Heaven [Del]

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.

23 Name: Anonymous : 2009-11-06 22:43 ID:khywL5Cg [Del]

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 :(

24 Name: Anonymous : 2009-11-07 22:00 ID:Heaven [Del]

>>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.

25 Name: Anonymous : 2009-12-31 11:00 ID:6SAR2y5l [Del]

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.

26 Name: !157ifIj00U : 2011-09-29 11:56 ID:Y+sjJch1 [Del]

fuck

27 Name: bob!157ifIj00U : 2011-09-29 11:57 ID:Y+sjJch1 [Del]

mehh

28 Name: !qMyXKpNzN6 : 2013-10-18 20:20 ID:4WyPOkIv [Del]

qwe

Name: Link:
Leave these fields empty (spam trap):
More options...
Verification: