Today's price for "nastiest code seen' goes to...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Today's price for "nastiest code seen' goes to...

timrowledge
Not from Squeak, thank goodness

----------------------------------------------------------------
decode: aString
        " Answer the decoded representation of aString which is an encoded series of bytes"
        |ret answer tmpstr decoded plain |
        plain := String new.
        ret := String new.
        1 to: aString size do: [ :x |
                ((String new copyWith: (aString at: x)) = '-') ifFalse: [
                        plain := plain, (String new copyWith: (aString at: x)).
                ]
        ].

        plain do: [ :x | ret := ret, (rctable keyAtValueEqual: (String new copyWith: x) ifAbsent: [ '' ] )  ].

        answer := OrderedCollection new.
        tmpstr := String new.
        1 to: ret size do: [ :x |
                tmpstr := tmpstr, (String new copyWith: (ret at: x)).
                (tmpstr size = 8) ifTrue: [
                        answer add: tmpstr.
                        tmpstr := String new.
                ]
        ].
        decoded := String new.
        answer do: [ :x | decoded := decoded, (String new copyWith: (Character value: (ctable keyAtValueEqual: x))) ].
        ^decoded asByteArray

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Never test for an error condition you don't know how to handle.



Reply | Threaded
Open this post in threaded view
|

Re: Today's price for "nastiest code seen' goes to...

timrowledge


> On 2020-04-03, at 3:59 PM, tim Rowledge <[hidden email]> wrote:
>
> Not from Squeak, thank goodness

Or maybe the best candidate is
rctable := Dictionary new.
[rctable add: (Association key: '00000' value: 'A').
rctable add: (Association key: '00001' value: 'B').
rctable add: (Association key: '00010' value: 'C').
rctable add: (Association key: '00011' value: 'D').
{snipped to avoid too much pain}
rctable add: (Association key: '11110' value: '5').
rctable add: (Association key: '11111' value: '8').
] value.

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Fractured Idiom:- FELIX NAVIDAD - Our cat has a boat



Reply | Threaded
Open this post in threaded view
|

Re: Today's price for "nastiest code seen' goes to...

marcel.taeumel
Can't you C the love tonight? ;o)

Am 04.04.2020 01:09:37 schrieb tim Rowledge <[hidden email]>:



> On 2020-04-03, at 3:59 PM, tim Rowledge wrote:
>
> Not from Squeak, thank goodness

Or maybe the best candidate is
rctable := Dictionary new.
[rctable add: (Association key: '00000' value: 'A').
rctable add: (Association key: '00001' value: 'B').
rctable add: (Association key: '00010' value: 'C').
rctable add: (Association key: '00011' value: 'D').
{snipped to avoid too much pain}
rctable add: (Association key: '11110' value: '5').
rctable add: (Association key: '11111' value: '8').
] value.

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Fractured Idiom:- FELIX NAVIDAD - Our cat has a boat





Reply | Threaded
Open this post in threaded view
|

Re: Today's price for "nastiest code seen' goes to...

Bruce O'Neel-2
In reply to this post by timrowledge


I smell a FORTAN DATA statement hiding there.

04 April 2020 01:09 tim Rowledge <[hidden email]> wrote:


> On 2020-04-03, at 3:59 PM, tim Rowledge wrote:
>
> Not from Squeak, thank goodness

Or maybe the best candidate is
rctable := Dictionary new.
[rctable add: (Association key: '00000' value: 'A').
rctable add: (Association key: '00001' value: 'B').
rctable add: (Association key: '00010' value: 'C').
rctable add: (Association key: '00011' value: 'D').
{snipped to avoid too much pain}
rctable add: (Association key: '11110' value: '5').
rctable add: (Association key: '11111' value: '8').
] value.

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Fractured Idiom:- FELIX NAVIDAD - Our cat has a boat







Reply | Threaded
Open this post in threaded view
|

Re: Today's price for "nastiest code seen' goes to...

timrowledge


> On 2020-04-04, at 8:27 AM, Bruce O'Neel <[hidden email]> wrote:
>
>
>
> I smell a FORTAN DATA statement hiding there.

Hmm, interesting thought, though I suspect Marcel is actually correct - it's part of a very lazy transcription of an implementation of the Blowfish algorithm, so likely the original was C. I really haven't seen anything that nasty in ages.

I mean, "String new copyWith:" eek!


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Useful random insult:- If you give him a penny for his thoughts, you get change back.