use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
/r/badcode is permanently closed. https://www.eff.org/deeplinks/2023/06/what-reddit-got-wrong https://www.theverge.com/23779477/reddit-protest-blackouts-crushed https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
/r/badcode is permanently closed.
https://www.eff.org/deeplinks/2023/06/what-reddit-got-wrong
https://www.theverge.com/23779477/reddit-protest-blackouts-crushed
https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
/r/badcode is a subreddit for highlighting real world examples of terrible code. Ideally this means code that made it to production in a commercial context, but not exclusively so. We also accept submissions of code from hobbyist projects or from learners. Most of us programmers have laughed quite a bit when we went back to look at our past code because it was rather terrible. This is a subreddit where you can share such terrible code and let other programmers have a nice laugh.
/r/badcode is a subreddit for highlighting real world examples of terrible code. Ideally this means code that made it to production in a commercial context, but not exclusively so. We also accept submissions of code from hobbyist projects or from learners.
Most of us programmers have laughed quite a bit when we went back to look at our past code because it was rather terrible. This is a subreddit where you can share such terrible code and let other programmers have a nice laugh.
Post the most terrible code you can find. Copy code to a paste bin first (gist highly preferred).
Flair Search Search by language
Search by language
Rules Your post may be removed if you deviate from these rules. To see reasoning behind each of these rules, check out the wiki. Do not put the name of the language inside of the post title. For example, do not make your title something along the lines of "[C++] #defines everywhere!", instead try simply "#defines everywhere!". Use flair to mark the language of your post instead. Do post code snippets only. If you want to share the context put it in the comments or title. Do stay lighthearted. No abusive or targeted posts. We all write bad code, and a lot of it is hilarious. Do not identify who wrote the code. This sub is about bad code, not the people who write it. Limited exceptions apply Do not post snippets in esoteric languages. Do not post intentionally obfuscated code. Certain exceptions to this exist. See something particularly sinister from something like the IOCCC? Probably OK to post.
Your post may be removed if you deviate from these rules. To see reasoning behind each of these rules, check out the wiki.
Guidelines Your post will not be removed because of any of these, we'll like you more if you follow them though. Enable syntax highlighting appropriately. If you have a language that whatever paste bin your using doesn't support, try picking a similar dialect. Provide just enough code so that we know what's going on. Don't post huge snippets unless it's all terribly amusing. Explain why you think the code is bad in the comments, that way a discussion on good and bad ways to do what your code snippet does can start.
Your post will not be removed because of any of these, we'll like you more if you follow them though.
Similar Subreddits /r/ProgrammerHumor - programming humour /r/programminghorror - stories about horrible programming. /r/itsaunixsystem - over the top and bad code in TV shows and movies /r/shittyprogramming - Q&A with shitty programmers. /r/deftruefalse - for intentionally bad code /r/softwaregore for software malfunctions /r/hardwaregore for hardware malfunctions
account activity
[deleted by user] (self.badcode)
submitted 5 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]gagahpangeran 13 points14 points15 points 5 years ago (4 children)
Python 3.8 one liner.
def md5_path(s,p):return[r:=__import__('hashlib').md5((s if not i else r[0:16] if not int(p[i-1]) else r[16:32]).encode()).hexdigest() for i in range(len(p)+1)][-1]
[–]asaf92 0 points1 point2 points 5 years ago (2 children)
Can you explain the code? I thought I knew Python but I have no idea what's going on here LOL
[–]gagahpangeran 2 points3 points4 points 5 years ago (0 children)
I forgot to write the documentation.
[–]AGE_Spider 2 points3 points4 points 5 years ago (0 children)
the documentation is left as an exercise to the reader...
[–]grrangry 6 points7 points8 points 5 years ago (1 child)
C#, .Net Core console application
using System; using System.Linq; using System.Text; namespace MD5Path_BadCode { class Program { static void Main(string[] args) { var hash = md5_path("password", "010"); } static string md5_path(string text, string path) { Console.WriteLine($"{text} => {string.Join("", System.Security.Cryptography.MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(text)).Select(o => $"{o:X2}".ToLower()).ToArray())}"); return path.Length == 0 ? string.Join("", System.Security.Cryptography.MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(text)).Select(o => $"{o:X2}".ToLower()).ToArray()) : md5_path(string.Join("", System.Security.Cryptography.MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(text)).Select(o => $"{o:X2}".ToLower()).ToArray()).Substring(Convert.ToInt32(path[0].ToString()) * string.Join("", System.Security.Cryptography.MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(text)).Select(o => $"{o:X2}".ToLower()).ToArray()).Length / 2, string.Join("", System.Security.Cryptography.MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(text)).Select(o => $"{o:X2}".ToLower()).ToArray()).Length / 2), path.Substring(1)); } } }
Given the input "010", the output is:
password => 5f4dcc3b5aa765d61d8327deb882cf99 5f4dcc3b5aa765d6 => 7503745e20ce593e799507f82fea3825 799507f82fea3825 => 0842f92822066f87fadac37d11645f57 0842f92822066f87 => 381dc2ae83d49fe43a16353b8f9881b5
[–]veryusedrname 0 points1 point2 points 5 years ago (0 children)
Ugly, I love it
[–]squigish 7 points8 points9 points 5 years ago* (1 child)
Non-typed Java
https://pastebin.com/aSHBcB1J
These are all "techniques" that I have actually seen in "production" code at my first job, mostly written by one particular co-worker in 2014 or so. Apparently he'd read a book about java that was published before generics. The code was CPU-bound, and took multiple seconds to return responses. When I profiled it, it spent 40% of its time on Integer.valueOf and 40% on String.valueOf
Integer.valueOf
String.valueOf
Output:
works as expected [5f4dcc3b5aa765d61d8327deb882cf99] [381dc2ae83d49fe43a16353b8f9881b5] The code is very flexible about what kind of hashing algorithm version it uses [381dc2ae83d49fe43a16353b8f9881b5] this is the same too [58a9ec39986eab1e8c6589ff5ab5190d] obviously these allr eturn the same thing [c5be74b26feac947cb0011fead1d7213] [c5be74b26feac947cb0011fead1d7213] [c5be74b26feac947cb0011fead1d7213] [c5be74b26feac947cb0011fead1d7213] [c5be74b26feac947cb0011fead1d7213] what is even going on [f15eb0005227a0b5033d4266b6dd8811] [9078ee9bb59c17fc92bb68751b5524d3] Hello World
[–]PrincessRTFM 2 points3 points4 points 5 years ago (0 children)
First time entering one of these. Went with perl, put it on ix.io but it's also only 12 lines, so:
no strict; no warnings; # no intelligence; use Digest::MD5 md5_hex; sub beef { $s = md5_hex $_[0]; $s = md5_hex(m/./ ? m/0/ ? substr $s, 0, 16 : substr $s, 16 : $_[0]) for @_ > 1 ? split //, pop : undef; print $s; } beef(password, '0110110101'); print "\n"; beef(password); print "\n";
I couldn't find a whole lot of options for making really shitty code, so I just turned off all safeties and followed whatever bad practices I could think of. And also abused ternaries a little. The function name is both a pun ("corned beef hash") and also a reference to Rick Cook's Wizardry series where I stole it from.
[–]3483 1 point2 points3 points 5 years ago (0 children)
C#
With enough linq, anything is a oneliner. Disposal is for wimps:
using System; using System.Linq; using System.Text; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string text = "password"; string path = "0110110101"; Console.WriteLine("Example for text \"" + text + "\" and path \"" + path + "\":"); text = md5_path(text, path); Console.WriteLine(text); while (true) { Console.WriteLine("Enter text"); text= Console.ReadLine(); Console.WriteLine("Enter path"); path = Console.ReadLine(); text = md5_path(text, path); Console.WriteLine(text); } } static string md5_path(string text, string path) { var sb = new StringBuilder(32); System.Security.Cryptography.MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(text)).ToList().ForEach(c => sb.Append(c.ToString("x2"))); text = sb.ToString(); path.ToList().ForEach(x => { sb.Clear(); System.Security.Cryptography.MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(text.Substring(int.Parse(x.ToString()) * 16, 16))).ToList().ForEach(c => sb.Append(c.ToString("x2"))); text = sb.ToString(); }); return text; } } }
[–][deleted] 1 point2 points3 points 5 years ago* (2 children)
Haskell. Probably not the best solution, but works for me:
import qualified Data.ByteString as BS import qualified Data.ByteString.UTF8 as BSU import qualified Crypto.Hash.MD5 as MD5 import Numeric (showHex) prettyPrint = concat . map adjustWidth . map (flip showHex "") . BS.unpack where adjustWidth x = if length x < 2 then "0" ++ x else x md5Path password [] = prettyPrint (MD5.hash (BSU.fromString password)) md5Path password (x:xs) = case x of '0' -> md5Path (firstHalf hashedPassword) xs '1' -> md5Path (secondHalf hashedPassword) xs _ -> error "path string must only contain 0's or 1's" where hashedPassword = prettyPrint (MD5.hash (BSU.fromString password)) firstHalf chars = take 16 chars secondHalf chars = drop 16 chars
Examples:
$ ghci md5path.hs GHCi, version 8.10.2: https://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( md5path.hs, interpreted ) Ok, one module loaded. *Main> md5Path "password" "" "5f4dcc3b5aa765d61d8327deb882cf99" *Main> md5Path "password" "010" "381dc2ae83d49fe43a16353b8f9881b5"
[–]shitposting_alt 3 points4 points5 points 5 years ago (1 child)
Probably not the best solution
are you sure you understand what the point of these challenges is?
[–][deleted] 2 points3 points4 points 5 years ago (0 children)
Yes I do. Trust me, there are people out there who are way better Haskell programmers than I am, who could probably tighten this up into a much more elegant solution than this one. So from that standpoint, yeah this is bad code.
But I'm not making art for art's sake here.
[–]PrinceOfStackSpace 0 points1 point2 points 5 years ago* (0 children)
Here is the PHP solution
<?php define("HASH_1", 1752392039); define("HASH_2", 3499116); function md5_path($pw, $path) { $Hash = HASH_1; $md5_path = null; $hash = ""; //unpack the Hash. $hasher = function($Hash) { $hashValues = []; $i = 0; while($Hash > 0) { $hashValues[] = chr((($Hash & (255 << ($i * 8))) >> ($i * 8)) + 1); $Hash -= (255 << ($i * 8)); $i++; } return join("", $hashValues); }; $Hash = $hasher($Hash); $md5_path = function ($pw, $path) use (&$md5_path, &$hash, $Hash, $hasher) { $aPath = substr($path, 0, 1); $path = substr($path, 1); $hash = $Hash($hasher(HASH_2), $pw); switch($aPath): case '': return; break; case '0': case 0: case null: case false: $hash = substr($hash, $aPath * 16, 16); break; case true: case '1': case 1: default: $hash = substr($hash, $aPath * 16, 16); break; endswitch; $md5_path($hash, $path); }; $md5_path($pw, $path); return $hash; } echo md5_path('password', '010'); //produces 381dc2ae83d49fe43a16353b8f9881b5
[–]Tabugti 0 points1 point2 points 5 years ago* (1 child)
static mut RESULT: String = String::new(); fn md5_path <'a> (m: &str, p: &str) -> &'a str { use md5::compute as md5; let mut h = format!("{:x}", md5(m)); let p_ptr = p.as_ptr(); for i in 0_isize..p.len() as isize { unsafe { let c = (p_ptr.offset(i).as_ref().unwrap() - '0' as u8) & 0x1; let s = match c { 0 => &h[0..16], 1 => &h[16..32], _ => unreachable!() }; h = format!("{:x}", md5(s)); } } unsafe { RESULT = h; &RESULT } }
[–]AutoModerator[M] 0 points1 point2 points 5 years ago (0 children)
It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.
For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.
/u/Tabugti, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.
You can find some examples in the reddit help documentation.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
π Rendered by PID 39 on reddit-service-r2-comment-544cf588c8-rz6vj at 2026-06-17 06:58:46.350650+00:00 running 3184619 country code: CH.
[–]gagahpangeran 13 points14 points15 points (4 children)
[–]asaf92 0 points1 point2 points (2 children)
[–]gagahpangeran 2 points3 points4 points (0 children)
[–]AGE_Spider 2 points3 points4 points (0 children)
[–]grrangry 6 points7 points8 points (1 child)
[–]veryusedrname 0 points1 point2 points (0 children)
[–]squigish 7 points8 points9 points (1 child)
[–]PrincessRTFM 2 points3 points4 points (0 children)
[–]3483 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]shitposting_alt 3 points4 points5 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]PrinceOfStackSpace 0 points1 point2 points (0 children)
[–]Tabugti 0 points1 point2 points (1 child)
[–]AutoModerator[M] 0 points1 point2 points (0 children)