Valhalla Legends Archive

Programming => General Programming => Java Programming => Topic started by: Joe[x86] on March 20, 2005, 08:46 PM

Title: UnCensor() Method Code
Post by: Joe[x86] on March 20, 2005, 08:46 PM
I just ported this to Java from LoRd[nK]'s Unknown Bot source code. This is untested, and I don't know if I did replace right, but I belive I did.

EDIT 3/20/05 10:02PM: Alphabetized list, removed duplicates, added more words I found from searching forums.

    //author JoeTheOdd
    //removes censoring from messages in public Bnet channels
    //@arg message - message recieved from Bnet
    //@return - uncensored message
    public static String uncensor(String message)
    {
        message = message.replaceAll("@$%!@%&",   "asshole");
        message = message.replaceAll("@$%!@!&",   "asswipe");
        message = message.replaceAll("#@%$!",     "bitch");
        message = message.replaceAll("$!@!$",     "chink");
        message = message.replaceAll("$%@%",      "clit");
        message = message.replaceAll("$!$%",      "cock");
        message = message.replaceAll("$&!%",      "cunt");
        message = message.replaceAll("%@$%",      "dick");
        message = message.replaceAll("%@%&!",     "dildo");
        message = message.replaceAll("&#&$%",     "erect");
        message = message.replaceAll("!@!@!%",    "faggot");
        message = message.replaceAll("!&$%",      "fuck");
        message = message.replaceAll("!@!$",      "gook");
        message = message.replaceAll("$@$&",      "kike");
        message = message.replaceAll("$%$",       "kkk");
        message = message.replaceAll("$%&!",      "klux");
        message = message.replaceAll("%&$#@#!",   "lesbian");
        message = message.replaceAll("&@$%&#$@%", "masturbat");
        message = message.replaceAll("!@!@#",     "nigga");
        message = message.replaceAll("!@!@&#",    "nigger");
        message = message.replaceAll("!@!@%&",    "nipple");
        message = message.replaceAll("!#!@$&",    "orgasm");
        message = message.replaceAll("!&!@$",     "penis");
        message = message.replaceAll("!&$%@",     "pussy");
        message = message.replaceAll("$!@%",      "shit");
        message = message.replaceAll("$%&%",      "slut");
        message = message.replaceAll("!@!@!@",    "vagina");
        message = message.replaceAll("!@!#&",     "whore");
        return message;
    }
Title: Re: UnCensor() Method Code
Post by: dxoigmn on March 20, 2005, 10:18 PM
One thing you'll want to becareful of is ordering of each replace.  For example, if you ran "!&$%@ !&$%" through this, it should ouput "fuck@ fuck" when it should ouput "pussy fuck."  Because "!&$%" is replaced first before "!&$%@", this happens. Other things to pay attention to would be only replacing whole words although I am not quite sure if battle.net partially replaces words (e.g. "fuckface" => "!&$%face" then it wouldn't be a problem).
Title: Re: UnCensor() Method Code
Post by: Joe[x86] on March 21, 2005, 07:05 AM
Whoops, guess alphabetizing it wasn't the best decision then, eh? I'll have to fix that after school.
Title: Re: UnCensor() Method Code
Post by: iago on March 21, 2005, 11:39 AM
Another thing I'd do is:

if(message.indexOf('$') >= 0 || message.indexOf('!') >= 0)
{
   ... do everything
}


That way it won't run all those replaces EVERY time.  And yes, I checked, every one of them has a $ or ! in it.
Title: Re: UnCensor() Method Code
Post by: Joe[x86] on March 21, 2005, 04:27 PM
Hmph. iago just loves optimization. VB programmers don't like that.

Fixed ordering and ported to C++ and VB.

Java:
//removes censoring from messages in public Bnet channels
//@arg message - message recieved from Bnet
//@return - uncensored message
public static String uncensor(String message)
{
    message = message.replaceAll("@$%!@%&",   "asshole");
    message = message.replaceAll("@$%!@!&",   "asswipe");
    message = message.replaceAll("#@%$!",     "bitch");
    message = message.replaceAll("$!@!$",     "chink");
    message = message.replaceAll("$%@%",      "clit");
    message = message.replaceAll("$!$%",      "cock");
    message = message.replaceAll("$&!%",      "cunt");
    message = message.replaceAll("%@$%",      "dick");
    message = message.replaceAll("%@%&!",     "dildo");
    message = message.replaceAll("&#&$%",     "erect");
    message = message.replaceAll("!@!@!%",    "faggot");
    message = message.replaceAll("!&$%@",     "pussy");
    message = message.replaceAll("!&$%",      "fuck");
    message = message.replaceAll("!@!$",      "gook");
    message = message.replaceAll("$@$&",      "kike");
    message = message.replaceAll("$%$",       "kkk");
    message = message.replaceAll("$%&!",      "klux");
    message = message.replaceAll("%&$#@#!",   "lesbian");
    message = message.replaceAll("&@$%&#$@%", "masturbat");
    message = message.replaceAll("!@!@#",     "nigga");
    message = message.replaceAll("!@!@&#",    "nigger");
    message = message.replaceAll("!@!@%&",    "nipple");
    message = message.replaceAll("!#!@$&",    "orgasm");
    message = message.replaceAll("!&!@$",     "penis");
    message = message.replaceAll("$!@%",      "shit");
    message = message.replaceAll("$%&%",      "slut");
    message = message.replaceAll("!@!@!@",    "vagina");
    message = message.replaceAll("!@!#&",     "whore");
    return message;
}


C++:
//removes censoring from messages in public Bnet channels
//@arg *txt - message recieved from Bnet
//@return - uncensored message
//
//I don't know C++ very well, but this doesn't
//appear to return anything, from my knoledge of the language.
//Thanks to Grok[vL] for help with this (indirectly, but still..)
void decensor(char *txt)
{
    replace(txt, "@$%!@%&",   "asshole");
    replace(txt, "@$%!@!&",   "asswipe");
    replace(txt, "#@%$!",     "bitch");
    replace(txt, "$!@!$",     "chink");
    replace(txt, "$%@%",      "clit");
    replace(txt, "$!$%",      "cock");
    replace(txt, "$&!%",      "cunt");
    replace(txt, "%@$%",      "dick");
    replace(txt, "%@%&!",     "dildo");
    replace(txt, "&#&$%",     "erect");
    replace(txt, "!@!@!%",    "faggot");
    replace(txt, "!&$%@",     "pussy");
    replace(txt, "!&$%",      "fuck");
    replace(txt, "!@!$",      "gook");
    replace(txt, "$@$&",      "kike");
    replace(txt, "$%$",       "kkk");
    replace(txt, "$%&!",      "klux");
    replace(txt, "%&$#@#!",   "lesbian");
    replace(txt, "&@$%&#$@%", "masturbat");
    replace(txt, "!@!@#",     "nigga");
    replace(txt, "!@!@&#",    "nigger");
    replace(txt, "!@!@%&",    "nipple");
    replace(txt, "!#!@$&",    "orgasm");
    replace(txt, "!&!@$",     "penis");
    replace(txt, "$!@%",      "shit");
    replace(txt, "$%&%",      "slut");
    replace(txt, "!@!@!@",    "vagina");
    replace(txt, "!@!#&",     "whore");
}


VB:
'//removes censoring from messages in public Bnet channels
'//@arg message - message recieved from Bnet
'//@return - uncensored message
Public Function uncensor(message As String) As String
    message = Replace(message, "@$%!@%&",   "asshole")
    message = Replace(message, "@$%!@!&",   "asswipe")
    message = Replace(message, "#@%$!",     "bitch")
    message = Replace(message, "$!@!$",     "chink")
    message = Replace(message, "$%@%",      "clit")
    message = Replace(message, "$!$%",      "cock")
    message = Replace(message, "$&!%",      "cunt")
    message = Replace(message, "%@$%",      "dick")
    message = Replace(message, "%@%&!",     "dildo")
    message = Replace(message, "&#&$%",     "erect")
    message = Replace(message, "!@!@!%",    "faggot")
    message = Replace(message, "!&$%@",     "pussy")
    message = Replace(message, "!&$%",      "fuck")
    message = Replace(message, "!@!$",      "gook")
    message = Replace(message, "$@$&",      "kike")
    message = Replace(message, "$%$",       "kkk")
    message = Replace(message, "$%&!",      "klux")
    message = Replace(message, "%&$#@#!",   "lesbian")
    message = Replace(message, "&@$%&#$@%", "masturbat")
    message = Replace(message, "!@!@#",     "nigga")
    message = Replace(message, "!@!@&#",    "nigger")
    message = Replace(message, "!@!@%&",    "nipple")
    message = Replace(message, "!#!@$&",    "orgasm")
    message = Replace(message, "!&!@$",     "penis")
    message = Replace(message, "$!@%",      "shit")
    message = Replace(message, "$%&%",      "slut")
    message = Replace(message, "!@!@!@",    "vagina")
    message = Replace(message, "!@!#&",     "whore")
    uncensor = message
End Function
Title: Re: UnCensor() Method Code
Post by: Eric on March 21, 2005, 04:46 PM
Quote from: Joey on March 20, 2005, 08:46 PM
I just ported this to Java from LoRd[nK]'s Unknown Bot source code. This is untested, and I don't know if I did replace right, but I belive I did.

EDIT 3/20/05 10:02PM: Alphabetized list, removed duplicates, added more words I found from searching forums.

    //author JoeTheOdd
    //removes censoring from messages in public Bnet channels
    //@arg message - message recieved from Bnet
    //@return - uncensored message
    public static String uncensor(String message)
    {
        message = message.replaceAll("@$%!@%&",   "asshole");
        message = message.replaceAll("@$%!@!&",   "asswipe");
        message = message.replaceAll("#@%$!",     "bitch");
        message = message.replaceAll("$!@!$",     "chink");
        message = message.replaceAll("$%@%",      "clit");
        message = message.replaceAll("$!$%",      "cock");
        message = message.replaceAll("$&!%",      "cunt");
        message = message.replaceAll("%@$%",      "dick");
        message = message.replaceAll("%@%&!",     "dildo");
        message = message.replaceAll("&#&$%",     "erect");
        message = message.replaceAll("!@!@!%",    "faggot");
        message = message.replaceAll("!&$%",      "fuck");
        message = message.replaceAll("!@!$",      "gook");
        message = message.replaceAll("$@$&",      "kike");
        message = message.replaceAll("$%$",       "kkk");
        message = message.replaceAll("$%&!",      "klux");
        message = message.replaceAll("%&$#@#!",   "lesbian");
        message = message.replaceAll("&@$%&#$@%", "masturbat");
        message = message.replaceAll("!@!@#",     "nigga");
        message = message.replaceAll("!@!@&#",    "nigger");
        message = message.replaceAll("!@!@%&",    "nipple");
        message = message.replaceAll("!#!@$&",    "orgasm");
        message = message.replaceAll("!&!@$",     "penis");
        message = message.replaceAll("!&$%@",     "pussy");
        message = message.replaceAll("$!@%",      "shit");
        message = message.replaceAll("$%&%",      "slut");
        message = message.replaceAll("!@!@!@",    "vagina");
        message = message.replaceAll("!@!#&",     "whore");
        return message;
    }


Note that you're not the author of a piece of code if all you did was port it.
Title: Re: UnCensor() Method Code
Post by: Newby on March 21, 2005, 06:07 PM
If I remember correctly, that function came from a bot made way before Unknown Bot.

Or one similar to it did, anyhow.
Title: Re: UnCensor() Method Code
Post by: MyndFyre on March 21, 2005, 06:29 PM
Quote from: Joey on March 21, 2005, 04:27 PM
Hmph. iago just loves optimization. VB programmers don't like that.
...unless you're actually a GOOD programmer trying to write GOOD code, in which case you DO like that.  You know, like professionals would?

Instead of making a scornful remark, why don't you attempt to LEARN from someone who is knowledgeable and experienced?
Title: Re: UnCensor() Method Code
Post by: iago on March 21, 2005, 06:33 PM
Quote from: MyndFyre on March 21, 2005, 06:29 PM
Instead of making a scornful remark

I'd call it a "joke".  He's said the same thing to me before :)
Title: Re: UnCensor() Method Code
Post by: MyndFyre on March 21, 2005, 06:36 PM
Quote from: iago on March 21, 2005, 06:33 PM
Quote from: MyndFyre on March 21, 2005, 06:29 PM
Instead of making a scornful remark

I'd call it a "joke".  He's said the same thing to me before :)

I would generally agree, except that he didn't actually incorporate your suggested change, which I think would have been, mm, 6 lines?  :P
Title: Re: UnCensor() Method Code
Post by: Lenny on March 21, 2005, 07:41 PM
I find it rather strange battle.net replaces a different set of censors on different words.  Almost makes me think some sort of formula was followed.

There appears to be some patterns, but nothing consistent from my first glance.  But if you notice, the length of each word does match its replacement...



Title: Re: UnCensor() Method Code
Post by: Ban on March 22, 2005, 09:38 AM
Or perhaps they just bashed random shift-numbers until they came up with a string of similiar length. If they had changed the length of the string the point of the original message would have never been gotten across; some things are needed to properly understand some sentences/messages
Title: Re: UnCensor() Method Code
Post by: Adron on March 22, 2005, 11:05 AM
Quote from: Ban on March 22, 2005, 09:38 AM
Or perhaps they just bashed random shift-numbers until they came up with a string of similiar length. If they had changed the length of the string the point of the original message would have never been gotten across; some things are needed to properly understand some sentences/messages

Or if they had changed the length of the message, they would have had to copy the resultant string to a new position in memory, incurring a performance loss. By ensuring that the replacement strings are the same length as the original strings, they can just overwrite the censored words inplace.
Title: Re: UnCensor() Method Code
Post by: iago on March 22, 2005, 12:30 PM
If they really wanted to hide it, they could have done "penis"->"*****", etc.  But they didn't, so they must have had some intention of letting people decode them :-/
Title: Re: UnCensor() Method Code
Post by: Lenny on March 22, 2005, 02:01 PM
This is one of the reasons I believe they could have went through a formula to censor the text.  Perhaps the obscenities are categorized, it just seems as if a pattern exists.  But it might only appear so because of the small character range given.

As far as performance goes, it would probably be best if the text wasn't censored at all, eliminating the need to filter every message passed to the server.  But since it is, optimizing it as much as possible would seem logical.

Title: Re: UnCensor() Method Code
Post by: Ban on March 23, 2005, 07:25 AM
Quote from: Adron on March 22, 2005, 11:05 AM
Quote from: Ban on March 22, 2005, 09:38 AM
Or perhaps they just bashed random shift-numbers until they came up with a string of similiar length. If they had changed the length of the string the point of the original message would have never been gotten across; some things are needed to properly understand some sentences/messages

Or if they had changed the length of the message, they would have had to copy the resultant string to a new position in memory, incurring a performance loss. By ensuring that the replacement strings are the same length as the original strings, they can just overwrite the censored words inplace.

Good point, I failed to consider that.

Quote
But it might only appear so because of the small character range given.

I would think that is more than likely,  as there are only 6 characters used in the replacements...
Title: Re: UnCensor() Method Code
Post by: R.a.B.B.i.T on March 24, 2005, 04:28 PM
To solve replacement issues: replace the longest words first.

@Lenny: You only need to check in public channels, which cuts the actual amount of filtering down.
Title: Re: UnCensor() Method Code
Post by: Adron on March 24, 2005, 04:56 PM
Quote from: rabbit on March 24, 2005, 04:28 PM
To solve replacement issues: replace the longest words first.

Hmm, so this would work?


        message = message.replaceAll("&@$%&#$@%", "masturbat");
        message = message.replaceAll("@$%!@%&",   "asshole");
        message = message.replaceAll("@$%!@!&",   "asswipe");
        message = message.replaceAll("%&$#@#!",   "lesbian");

        message = message.replaceAll("!@!@!%",    "faggot");
        message = message.replaceAll("!@!@&#",    "nigger");
        message = message.replaceAll("!@!@%&",    "nipple");
        message = message.replaceAll("!#!@$&",    "orgasm");
        message = message.replaceAll("!@!@!@",    "vagina");

        message = message.replaceAll("#@%$!",     "bitch");
        message = message.replaceAll("$!@!$",     "chink");
        message = message.replaceAll("%@%&!",     "dildo");
        message = message.replaceAll("&#&$%",     "erect");
        message = message.replaceAll("!@!@#",     "nigga");
        message = message.replaceAll("!&!@$",     "penis");
        message = message.replaceAll("!&$%@",     "pussy");
        message = message.replaceAll("!@!#&",     "whore");

        message = message.replaceAll("$%@%",      "clit");
        message = message.replaceAll("$!$%",      "cock");
        message = message.replaceAll("$&!%",      "cunt");
        message = message.replaceAll("%@$%",      "dick");
        message = message.replaceAll("!&$%",      "fuck");
        message = message.replaceAll("!@!$",      "gook");
        message = message.replaceAll("$@$&",      "kike");
        message = message.replaceAll("$%&!",      "klux");
        message = message.replaceAll("$!@%",      "shit");
        message = message.replaceAll("$%&%",      "slut");

        message = message.replaceAll("$%$",       "kkk");


Try it on "vaginaerect"?
Title: Re: UnCensor() Method Code
Post by: Lenny on March 24, 2005, 04:59 PM
Regardless, it would still be a waste of server perfomance.  And if Adron is correct, they're trying to optimize something that isn't necessary.

But I personally think an 'uncensor()' method is a novelty feature that bots need not have. 

Why battle.net chose to have a distinct censor pattern for each word is beyond me. 

Title: Re: UnCensor() Method Code
Post by: Warrior on March 24, 2005, 05:11 PM
What would be funny is if they just put random letters together and some of you are boggling your minds for nothing :P
Title: Re: UnCensor() Method Code
Post by: Joe[x86] on March 24, 2005, 08:20 PM
Quote from: MyndFyre on March 21, 2005, 06:36 PM
Quote from: iago on March 21, 2005, 06:33 PM
Quote from: MyndFyre on March 21, 2005, 06:29 PM
Instead of making a scornful remark

I'd call it a "joke".  He's said the same thing to me before :)

I would generally agree, except that he didn't actually incorporate your suggested change, which I think would have been, mm, 6 lines?  :P

Thats because I haven't had time. 3rd quarter just ended at my school, and I had about a month's worth of homework (I never did any of it when it was asigned) over the past few days. I was just joking, and I asumed that nobody would take it as a "scornful remark". Its just the kind of thing iago and I do.


@LoRd[nK]: Good to know you have nothing better to do than to try to shit on the little guy's day. Atleast I give credit for other's work incorporated into mine. Also, my code is nicely tabbed and easy to follow, unlike your wonderful code (http://www.cold-chaos.net/lord/Files/Battle.net/BinaryBots/FLooDBoT.zip).
Title: Re: UnCensor() Method Code
Post by: iago on March 24, 2005, 08:34 PM
Quote from: Joey on March 24, 2005, 08:20 PM
I was just joking, and I asumed that nobody would take it as a "scornful remark". Its just the kind of thing iago and I do.
That's what I said :P

Quote@LoRd[nK]: Good to know you have nothing better to do than to try to shit on the little guy's day. Atleast I give credit for other's work incorporated into mine. Also, my code is nicely tabbed and easy to follow, unlike your wonderful code (http://www.cold-chaos.net/lord/Files/Battle.net/BinaryBots/FLooDBoT.zip).
Let's be nice here, children; if you want to be mad then take it to PM.
Title: Re: UnCensor() Method Code
Post by: Joe[x86] on March 24, 2005, 08:51 PM
I'll shut my mouth if he shuts his. I'm done for now. I just wanted to remind him he hasn't exactly perfect either.

Due to the emmence ammount of work it takes to post every single update at a good 5 forums, the code updates will only be posted here (https://www.x86labs.org/forum/index.php?topic=890.0). Thanks to everyone for their suggestions.
Title: Re: UnCensor() Method Code
Post by: iago on March 24, 2005, 09:03 PM
Quote from: Joey on March 24, 2005, 08:51 PM
I'll shut my mouth if he shuts his. I'm done for now. I just wanted to remind him he hasn't exactly perfect either.

Far from it, but this is the wrong place to get into it.