Download pwdgen.tar.gz

INTERCAL: Practically Impossible

A very good friend of mine has been experimenting with trying to coax Chat-GPT4 to successfully do basic coding tasks. So have a lot of people these days, of course. In an idle moment, though, my friend submitted the following query:

Please write a password generation program using the Intercal computer programming language.

And this was the program's response:

INTERCAL is a esoteric programming language that was created as a parody. It's known for its complex and counter-intuitive syntax. Writing a password generation program in INTERCAL would be quite a challenge and the result would be difficult to understand and maintain.

INTERCAL has no built-in functions for random number generation or string manipulation, which are typically used in password generation programs. It also lacks the ability to interact with external libraries that could provide these functionalities. Therefore, creating a password generator in INTERCAL is practically impossible.

However, if you're interested in INTERCAL, here's a simple program that prints "Hello, World!" to give you an idea of what INTERCAL code looks like:

DO :1 <- #13 PLEASE DO :1 SUB #1 <- #238 DO :1 SUB #2 <- #108 DO :1 SUB #3 <- #112 DO :1 SUB #4 <- #0 DO :1 SUB #5 <- #64 DO :1 SUB #6 <- #194 DO :1 SUB #7 <- #48 PLEASE READ OUT :1 PLEASE GIVE UP

This program uses the "DO" statement to assign values to variables, and the "PLEASE READ OUT" statement to print the result. The numbers are in a base-10 representation of the ASCII values of the characters in "Hello, World!".

If you're interested in password generation, I'd recommend using a language that's better suited to the task, such as Python, Java, or JavaScript. These languages have built-in libraries for random number generation and string manipulation, and are widely used for practical programming tasks.

Now, I have a few things to say about this response, both good and bad. But before I get properly into the weeds, let me just share with you my friend's followup comment:

Oh, I'm sorry. Was this too difficult for you? I know someone who wrote a floating-point library for Intercal, so I thought maybe an generative AI could write a simple thing like a password generator. Forgive me for troubling you.

This here? This is why we are such good friends. But anyway, Chat-GPT's response to his bit of snark is more or less what you would expect:

I apologize if my previous response gave the impression that it's impossible to write a password generator in INTERCAL. While INTERCAL is indeed a challenging language due to its esoteric nature, it's not impossible to create a password generator. However, it would be quite complex and not straightforward due to the language's limitations and unique syntax.

The main challenge is that INTERCAL lacks built-in functions for random number generation or string manipulation, which are typically used in password generation programs. It also lacks the ability to interact with external libraries that could provide these functionalities.

If someone has written a floating-point library for INTERCAL, they have likely implemented a significant amount of functionality that is not native to the language. This is a significant achievement, but it's not something that can be easily replicated in a short amount of time.

Again, I apologize if my previous response was disappointing. If you have any other questions or need help with anything else, please don't hesitate to ask.

As I've noticed in the past, followup responses from Chat-GPT generally tend to be a bit more factually accurate than initial responses. (Whether that is due to gleaning cues from human feedback, or just because the program tries alternate options in response to any complaint, is a question for others to explore.)

If you haven't already guessed, I am the person who wrote a floating-point library for INTERCAL.¹ Chat-GPT is correct that it required "a significant amount of functionality that is not native to the language", but I mean duh. So did all the floating-point libraries that people wrote back in the 1990s, when floating-point coprocessors were optional. So what? That observation is hardly relevant to this query in particular or INTERCAL in general. (Though I suppose one could argue that my friend's snark isn't really relevant either. Fair enough. However, I do find it interesting how Chat-GPT responds so politely to the type of shade that might have spurred a more human programmer into action.) I will say that while the floating-point library was technically challenging to write, probably the most challenging INTERCAL program I've written is the quine that I managed to squeeze down to under 4kB.²

Now, I haven't done any significant INTERCAL programming in decades. After some futile attemtps to get a job as an INTERCAL programmer, I was forced to spend my time acquiring more marketable resume bullet points, and my INTERCAL skills have lain largely fallow since. But don't think that they have deserted me entirely—nor that I care any less about defending my chosen esoteric language from misinformation promulgated by thoughtless neural networks.

But I have very little to say about the second response. It's mostly a repetition of a few points made in the first response, along with one or two mostly accurate asides.

So. Let's examine that first response, shall we?

First, a positive. Kudos to Chat-GPT for spelling the language as INTERCAL (all uppercase), despite my friend's use of the more common spelling. I do appreciate that this chatbot is doing its part to promulgate the original manual's rendering. Yes, I realize that the habit of writing computer language names in all-caps died out with the advent of display devices with lowercase letter support, and languages like FORTRAN and LISP and BASIC were all rebranded thusly. But I mean come on—if any language should evince disinterest in escaping the 1970s, it is INTERCAL.

As for the rest, Chat-GPT remains true to form in that, like most bullshitters, it succeeds most when it confines itself to generalities. The moment it blunders into specificity, it gets itself in trouble.

First, it states that a password generator written in INTERCAL "would be difficult to understand and maintain." Fine, I'll grant that—it's about as true as a subjective statement can be. Then, it claims that "INTERCAL has no built-in functions for random number generation or string manipulation". I beg your pardon.

Arguably, most computer languages have no built-in functions for random number generation, since that functionality is typically relegated to a standard library. Nonetheless, pseudo-random number generation only requires a couple of basic arithmetic operations, so even if it wasn't in the standard library, it's not hard to whistle up some numbers that are random enough for a simple password generator.

That said, you might be tempted to give me a hard time and point out that in INTERCAL, even basic arithmetic operators are only supplied by the standard library, and so therefore Chat-GPT's assertion is still technically accurate. (You might argue this even though you really ought to know that as soon as you move your goalposts to "technically accurate", you're already in trouble.) If you did argue this, I would freely acknowledge that your premise is true. But it doesn't make a difference, you dipstick, because INTERCAL has random-number generation built right into the language.

Gaze upon this, and weep at its elegance:

DO .1 <- #0 DO %50 .1 <- #1

After the above two lines execute, the variable .1 will be equally likely to contain either zero or one. The %50 in the second line means that it will only execute half of the time the program runs. Far from being difficult, randomness is a language primitive. I ask you, here and now, what could be more transparent?

As for Chat-GPT's comment about a lack of string manipulation—sure, that is completely true. And completely irrelevant. Nobody needs string manipulation to write a bloody password generator (unless maybe your password generator is double-checking to make sure the RNG didn't go and dredge up something like "passw0rd" or "sexgod69"). The fact that Chat-GPT throws "no string manipulation" down like some kind of trump card merely demonstrates that it doesn't fully grasp the nature of the suggested task.

But this is no surprise, for if Chat-GPT possessed a scintilla of self-awareness, we would not have been treated to the rest of its response. "However, if you're interested in INTERCAL, here's a simple program that prints 'Hello, World!'"

Oh Chat-GPT, I would have respected you more if you had simply shut up.

Now, it isn't much of a surprise that Chat-GPT selected hello-world to demonstrate its knowledge of INTERCAL programming. My hunch is that a signifcant percentage of all INTERCAL programs written are hello-world programs (as that is usually enough to convince most programmers that first, the INTERCAL compiler is real, and second, that they have better things to do with their time). Ergo, I imagine that this is more likely than any other "task" to have enough training data to keep Chat-GPT on the rails from soup to nuts. Let us venture forth and find out how well it did.

DO :1 <- #13 PLEASE DO :1 SUB #1 <- #238 DO :1 SUB #2 <- #108 DO :1 SUB #3 <- #112 DO :1 SUB #4 <- #0 DO :1 SUB #5 <- #64 DO :1 SUB #6 <- #194 DO :1 SUB #7 <- #48 PLEASE READ OUT :1 PLEASE GIVE UP

(Side note: I won't fault the interface for doing such a terrible job of syntax highlighting, because how can I get mad at anyone for assuming that no one is likely to submit INTERCAL code to their syntax-highlighting routine? At the same time, I'm sure as hell not going to promulgate its piebald spatter any further.)

I'll give it one thing. This program does compile successfully. Unfortunately that's not a very high bar to clear, as INTERCAL treats syntax errors as run-time exceptions. The syntax error this particular bit of code sports is that :1 is not an array, and thus cannot be subscripted. The compiled program crashes on line two: "E" for effort.

Still, let's be generous and fix that. It's the type of mistake any newbie might make, if they hadn't bothered to read the documentation at all. We will replace :1 with ,1 throughout, as this is clearly what was intended. This version of the program runs! It even outputs a string, namely: "Hello,       ". Which is exactly what one would expect from even a cursory examination of the code. The program allocates a 13-element array, but only the first seven elements are initialized.

I'm unsure exactly how Chat-GPT managed to regurgitate the first half of a valid array initialization sequence and then still get lost. My vague suspicion is that the next line of whatever actual hello-world INTERCAL program that Chat-GPT is indirectly cadging from began with PLEASE, and this disruption of the pattern was enough for its Markov-chain logic to leap across the rest of the initialization code to the PLEASE READ OUT statement at the end of the program.

The bot's lack of understanding is further demonstrated by the explication it supplies, which vaguely suggests that DO is an assignment statement. (To be clear, <- is the assignment operator; DO and PLEASE are simply how every statement is introduced.). The next sentence then blithely comments that the array values "are in a base-10 representation of the ASCII values of the characters." I mean, okay? Like, thanks for reassuring me that the values are not EBCDIC characters in base 11; I had assumed that already but with INTERCAL it's not always safe to make assumptions. But, no thanks for blatantly glossing over the fact that the array values are actually bit-reversed sequential differences of ASCII values. Presumably that nugget of information was too picayune to be worth mentioning.

Ultimately, though, I do have to award Chat-GPT points for successfully pretending to understand that the partially-digested sequence it produced was (originally) an INTERCAL program, and one that output a traditional salutary greeting.

Finally, I must address the statement that prompted me to sit down in front of my keyboard and bang out this whole ridiculous essay, intsead of moving on with my life. Smack in the middle of this mulligatawny, Chat-GPT opines:

"Therefore, creating a password generator in INTERCAL is practically impossible."

Okay, you know what, Chat-GPT? Fuck you. Yes, it is perfectly valid, if not actually de rigeur, for an INTERCAL programmer to cast aspersions upon the language at every opportunity. But, as we have already established, you are not an INTERCAL programmer. You've made that blisteringly clear with your literally half-assed sample program, and you have made it doubly clear with that comment. Granted, INTERCAL may be a mad, freakish chimera of a parody of IBM mainframe language design crossed with the gleeful chaos of the Turing tarpit. But it's my mad, freakish chimera of a … oh you get the point.

So here you go, you libellous word bucket. The following INTERCAL program is a password generator. When executed, it creates passwords of length 16. It avoids using various characters that are easily confused with each other (such as "1", "I", "i", "l", "!", and "/"). Generated passwords are guaranteed to include at least one digit and one punctuation mark.

PLEASE NOTE THAT THIS IS A PASSWORD GENERATION PROGRAM PLEASE NOTE THAT IT WAS WRITTEN BY BRIAN RAITER IN MMXXIII PLEASE NOTE THAT IT GENERATES 16-CHARACTER PASSWORDS PLEASE NOTE THAT PASSWORDS INCLUDE BOTH DIGITS AND PUNCTUATION PLEASE NOTE THAT EASILY MISREAD CHARACTERS ARE ESCHEWED DO NOTE THE INITIALIZATION OF THE CHARACTER SET PLEASE DO ,6 <- #127 PLEASE NOTE DIGITS TWO THROUGH NINE DO ,6SUB#1 <- #76 DO ,6SUB#9 <- #108 DO ,6SUB#3 <- #204 DO ,6SUB#11 <- #236 DO ,6SUB#5 <- #44 DO ,6SUB#13 <- #28 DO ,6SUB#7 <- #172 DO ,6SUB#15 <- #156 PLEASE NOTE EIGHT PUNCTUATION MARKS DO ,6SUB#17 <- #164 DO ,6SUB#25 <- #180 DO ,6SUB#19 <- #100 DO ,6SUB#27 <- #60 DO ,6SUB#21 <- #84 DO ,6SUB#29 <- #124 DO ,6SUB#23 <- #212 DO ,6SUB#31 <- #252 PLEASE NOTE TWENTY-FOUR CAPITAL LETTERS DO ,6SUB#33 <- #130 DO ,6SUB#57 <- #114 DO ,6SUB#35 <- #66 DO ,6SUB#59 <- #10 DO ,6SUB#37 <- #194 DO ,6SUB#61 <- #138 DO ,6SUB#39 <- #34 DO ,6SUB#63 <- #74 DO ,6SUB#41 <- #162 DO ,6SUB#65 <- #202 DO ,6SUB#43 <- #98 DO ,6SUB#67 <- #42 DO ,6SUB#45 <- #226 DO ,6SUB#69 <- #170 DO ,6SUB#47 <- #18 DO ,6SUB#71 <- #106 DO ,6SUB#49 <- #82 DO ,6SUB#73 <- #234 DO ,6SUB#51 <- #210 DO ,6SUB#75 <- #26 DO ,6SUB#53 <- #50 DO ,6SUB#77 <- #154 DO ,6SUB#55 <- #178 DO ,6SUB#79 <- #90 PLEASE NOTE TWENTY-THREE LOWERCASE LETTERS PLUS UNDERSCORE DO ,6SUB#81 <- #250 DO ,6SUB#105 <- #118 DO ,6SUB#83 <- #134 DO ,6SUB#107 <- #14 DO ,6SUB#85 <- #70 DO ,6SUB#109 <- #142 DO ,6SUB#87 <- #198 DO ,6SUB#111 <- #78 DO ,6SUB#89 <- #38 DO ,6SUB#113 <- #206 DO ,6SUB#91 <- #166 DO ,6SUB#115 <- #46 DO ,6SUB#93 <- #102 DO ,6SUB#117 <- #174 DO ,6SUB#95 <- #230 DO ,6SUB#119 <- #110 DO ,6SUB#97 <- #22 DO ,6SUB#121 <- #238 DO ,6SUB#99 <- #86 DO ,6SUB#123 <- #30 DO ,6SUB#101 <- #214 DO ,6SUB#125 <- #158 DO ,6SUB#103 <- #182 DO ,6SUB#127 <- #94 DO NOTE THE CHOOSING OF FORCED SPOTS FOR NUMBERS AND PUNCTUATION PLEASE NOTE THAT THESE WILL ONLY BE USED IF NECESSARY PLEASE DO .8 <- #0 PLEASE DO %50 .8 <- #1 PLEASE DO %50 .8 <- '#1$.8'~#3 PLEASE DO %50 .8 <- '#2$.8'~#13 PLEASE DO %50 .8 <- '#4$.8'~#53 PLEASE DO .9 <- #0 PLEASE DO %50 .9 <- #1 PLEASE DO %50 .9 <- '#1$.9'~#3 PLEASE DO %50 .9 <- '#2$.9'~#13 PLEASE DO %50 .9 <- '#4$.9'~#53 PLEASE DO NOT LET THE TWO SPOTS BE EQUAL DO .5 <- '#1$"!8$.9'~#1"'~#3 DO (4) NEXT DO NOTE THE INVOCATION OF THE MAIN ROUTINE DO ,1 <- #1 PLEASE DO .1 <- #0 DO (1) NEXT DO NOTE THE READING OUT OF A FINAL NEWLINE BEFORE GIVING UP DO .1 <- ,1SUB#1 DO .2 <- #80 DO (1010) NEXT DO ,1SUB#1 <- .3 PLEASE READ OUT ,1 PLEASE GIVE UP DO NOTE THAT .8 WILL BE CHANGED WHEN IT CLASHES WITH .9 (4) DO (5) NEXT DO .8 <- '?.8$#15'~#170 PLEASE RESUME #1 (5) DO (1001) NEXT DO NOTE THE MAIN LOOP WHICH BEGINS HERE (1) DO COME FROM (9) PLEASE DO .6 <- #8 PLEASE DO %50 .6 <- #9 PLEASE DO %50 .6 <- '#1$.6'~#83 PLEASE DO %50 .6 <- '#2$.6'~#77 DO NOTE THAT THIS SPOT MIGHT BE FORCED TO BE A NUMBER DO .5 <- '#1$"#15~'"?.1$.9"~#85'"'~#3 DO (3) NEXT DO NOTE THAT IT MIGHT BE FORCED TO BE A PUNCTUATION MARK INSTEAD PLEASE DO .6 <- .6~#7 DO .5 <- '#1$"#15~'"?.1$.8"~#85'"'~#3 DO (3) NEXT PLEASE DO %50 .6 <- '#4$.6'~#53 PLEASE DO %50 .6 <- '#8$.6'~#213 PLEASE DO %50 .6 <- '#16$.6'~#853 PLEASE NOTE THAT DIGITS AND PUNCTUATION MARKS ARE CHECKED FOR DO .5 <- "#1$!V6~#16'"~#3 DO (6) NEXT DO (2) NEXT DO NOTE THAT IN SUCH AN EVENT THE PRE-CHOSEN SPOT IS DROPPED (6) DO (5) NEXT PLEASE FORGET #1 DO .5 <- !6$#16'~#384 DO (7) NEXT DO .9 <- #0 DO (2) NEXT (7) DO (5) NEXT PLEASE FORGET #1 DO .8 <- #0 DO (2) NEXT (3) DO (5) NEXT PLEASE NOTE THE READING OUT OF THE SELECTED CHARACTER (2) PLEASE FORGET #1 PLEASE STASH .1 DO .1 <- ,1SUB#1 DO .2 <- ,6SUB"!6$#1'~#2731" DO (1010) NEXT DO ,1SUB#1 <- .3~#255 PLEASE READ OUT ,1 DO ,1SUB#1 <- .2 PLEASE RETRIEVE .1 DO NOTE THE MAIN LOOP ENDS HERE DO (1020) NEXT DO .5 <- !1$#32'~#1536 (9) DO (5) NEXT

Far from being practically impossible, I wrote it in an afternoon. (Okay, plus a bit of post-1.0 debugging in the evening.) That may strike you as rather slow for such a straightforward task, but that's because you don't realize that there is no such thing as "straightforward" when it comes to INTERCAL. (Also, like I said, my INTERCAL skills are rusty.)

Next time you trash-talk my beloved INTERCAL, you better understand what you're saying. Got that? All right. Thank you for your attention: breadbox out.

Post Scriptum: The program shown here in written in the C-INTERCAL dialect, in order to take advantage of its character-based output capabilities. But for the sake of purists (i.e. myself), I also wrote a version that constrains itself to the language defined by the original 1972 Princeton compiler. Instead of character output, it simply displays a sequence of sixteen numbers (as Roman numerals, it should go without saying), which form the chosen password when read as ASCII values. Alternately, I have provided a third version will output the password as EBCDIC values instead. Never say that INTERCAL programmers don't care about portability. A tarball containing all three versions can be downloaded from the link below.³

Post Post Scriptum: Chat-GPT4 has responded to this essay: see Practically Impossible, revisited.

  1. The INTERCAL floating-point library.  
  2. The INTERCAL quine.  
  3. The source code for the INTERCAL password generator(s).  

Brian Raiter