Skip to main content
The National Cipher Challenge

Challenge 10B

A Tale of 2 Secrets Forums T.E.M.P.E.S.T. Challenge 10B

  • This topic has 274 replies, 92 voices, and was last updated 1 week ago by _madness_.
Viewing 7 posts - 271 through 277 (of 277 total)
  • Author
    Posts
  • #115352
    Crackerjack_404
    Participant

    @AES_of_spades

    To be honest, I learned Python during GCSEs, but just the basics to get me a good grade. Having never done any programming before that, most of my coding experience came from writing solutions for the cipher challenge problems, which in turn helped me in A-Level and just improving thinking skills in general. I’m at uni now and most of the skills I’ve learned is thanks to the experienced gained by taking part in this competition.

    I might be biased, but I genuinely think the best way to learn is by just doing projects. Every now and then I start a new maths/coding project, not necessarily with the intention of always finishing it, but I always end up learning a lot in the process. So pick something you enjoy and do it for fun, not just because you think you “should”. As much as I loved writing code for solving challenges, there were definitely times when it became stressful, and if you find that happening, it’s usually a sign you should switch things up for a bit. Sometimes that means working on a different problem, and sometimes it means doing something completely different. At one point I picked up crocheting, and I vividly remember crocheting while debugging my A-Level code because I was getting so frustrated with a program that refused to run. Weirdly, that kind of break actually helped more than staring at the screen ever did.

    There are plenty of good books and resources which the far more experienced here will be happy to recommend, but I’ve mostly relied on learning by searching things as I go, because I personally find that dense books can be overwhelming when you don’t yet know what’s relevant. There’s a very high chance that whatever problem you’re stuck on has been hit by someone before (funnily enough this is true in both programming and life…). I’ve also been grateful to have friends and people around me who were there to help, so I’d suggest finding a similar community for yourself. It makes a massive impact being around people who share a similar goal to you than doing everything by yourself. When I first started programming, I never imagined I’d be able to solve the kinds of problems I can today. It can be really daunting at first, especially when you’re looking at other people’s code and it all feels incomprehensible, but you have to keep things in perspective and trust the learning process, it genuinely does add up over time!

    Hope that helps!

    P.S – I’ll be kind and explain what went in my thinking with the golfing of Madness’ initial solution, think of the below as the comments that were left as an exercise to the reader.

    
    print((lambda c: "".join(("SHADOWBCEFGIKLMNPQRTUVXY"[(("A23456789XJQK".index(c[i]) + 13*"CDHS".index(c[i+1]))%6)+6*((("A23456789XJQK".index(c[i+2]) + 13*"CDHS".index(c[i+3]) - 36))//4)] + "FULHEARTBCDGIKMNOPQSVWXY"[((("A23456789XJQK".index(c[i+2]) + 13*"CDHS".index(c[i+3]) - 36))%4)+4*((("A23456789XJQK".index(c[i]) + 13*"CDHS".index(c[i+1]))//6))]) for i in range(0,len(c),4)))("7CXS3 H6S7C...".replace(" ", "")))
    

    The key idea was first knowing what I wanted the code to do. So I knew how the decryption logic from the better readable version- i.e. I take the text, remove the spaces, process it in chunks of 4 chars, turn those into cards, convert those into numbers, recombine the coords, and look up the two letters in the grid.

    Once I had that, the rest was just fancy implementation. I knew I was wanted to write in one line as a joke, and Python has thing called list comprehensions, which let you just build a list by doing X for every i in this rage. So my one line solution was basically to write a function (and use lambda so I call it immediately) which would take each block of 4 chars, compute the two output letters using the rule, and then join the all together in the string. It looks evil cuz all the intermediate steps are inlined instead of given nice variable names but it’s still exactly the same algorithm as the more readable version. If you have any specific questions about the code I’d happy to (try) and answer them.

    #115347
    BobD
    Participant

    @AES_of_spades Certainly the programs you refer to are hugely impressive. However, as you imply, they are not easy to follow!!
    My best advice would be to concentrate on writing programs which are clearly structured and self-documenting; this is especially important when working together with others in a group. I am sure most experienced programmers will have been faced with looking back on a program which they had written a while ago, trying to fathom out how on earth it works!
    The days are gone when, faced with a few kilobytes of memory, programs had to be squeezed into the small amount of space available.

    This is quite right of course, but it is still a fascinating challenge to try to boil the algorithm down to its barest bones. Another very interesting issue is that to properly understand how quantum computers operate it is necessary to go further and to reduce an algorithm to its structure in terms of logic gates. Each of the classical gates has a quantum counterpart and converting an algorithm (like Shor’s algorithm) to quantum form more or less consists of replacing the classical AND/OR/NOT gates with QAND, QOR, QNOT. To do that you need to understand how arithmetic operations are encoded on a chip. So for example you probably need to understand how a 2-bit adder works to add 2 digit binary numbers using (classical) logic gates. The connection with the compressed algorithms you are all (impressively) delivering here, is that quantum gates are very hard and expensive to build and assemble, and compressed algorithms could be cheaper to convert, so while properly documented, human readable code is a very good idea for classical computers, high efficiency algorithms which reduce the complexity of the circuits needed to run them still have a place! Harry

    #115297
    _madness_
    Participant

    They were links to alphabet cards and blank playing cards for sale on Amazon.

    #115253
    F6EXB_the_frenchy
    Participant

    @madness
    Program to help reconstruct the 10B grid as clues are found.
    The encrypted text should be placed in the same directory as the .py program and in my program it is called ‘Mission.txt’.

    # ------------------------- Décodage du  10B 2025 -----------------------
    # Décodage du chiffre 4squares avec jeu de 52 cartes
    # ------------------------------------------------------------------------------
    
    import re
    
    #debut = process_time()
    
    CT1 =       ["AC","2C","3C","4C","5C","6C",
                 "7C","8C","9C","XC","JC","QC",
                 "KC","AD","2D","3D","4D","5D",
                 "6D","7D","8D","9D","XD","JD",
                 "QD","KD","AH","2H","3H","4H",
                 "5H","6H","7H","8H","9H","XH"]
    
    CT2 = 	    ["JH","QH","KH","AS", 
                 "2S","3S","4S","5S", 
                 "6S","7S","8S","9S", 
                 "XS","JS","QS","KS"] 
    
    alphabet_1 = [".",".",".",".",".",".",     # ["JH","QH","KH","AS",
                  "b",".","e","f","g",".",	   #  "2S","3S","4S","5S",
                  ".","l","m","n","p","q",	   #  "6S","7S","8S","9S",
                  "r","t","u","v",".","."]	   #  "XS","JS","QS","KS"]
    
    alphabet_2 = [".",".","l",".",# "AC","2C","3C","4C","5C","6C"
                  "e",".","r","t",# "7C","8C","9C","XC","JC","QC"
                  "b",".",".","g",# "KC","AD","2D","3D","4D","5D"
                  ".","k","m","n",# "6D","7D","8D","9D","XD","JD"
                  "o",".",".","s",# "QD","KD","AH","2H","3H","4H"
                  ".",".",".","."]# "5H","6H","7H","8H","9H","XH"
    
    fichier = open("Mission.txt", "r", encoding='utf-8')  # Texte à déchiffrer.
    texte = fichier.read()
    #print(texte)
    fichier.close()
    
    texte = re.sub('[^A-Z0-9]|\\s','',texte.upper()) # Supprime ce qui n'est pas alphanumérique.
    #print(texte)
    
    long = len(texte)
    clair = ""
    for i in range(0,long,4):
        carte_1 = texte[i:i+2]
        #print ("carte 1 : ", carte_1)
        rang_1 = CT1.index(carte_1)
        #print ("rang carte 1 :", rang_1)
        carte_1_x = rang_1 //6
        carte_1_y = rang_1 %6
        #print ("x :", carte_1_x, "y :", carte_1_y, "\n")
    
        carte_2 = texte[i+2:i+4]
        #print ("carte 2 : ", carte_2)
        rang_2 = CT2.index(carte_2)
        #print ("rang carte 2 :", rang_2)
        carte_2_x = rang_2 //4
        carte_2_y = rang_2 %4
        #print ("x :", carte_2_x, "y :", carte_2_y, "\n")
        
        clair_1 = alphabet_1[carte_2_x * 6 + carte_1_y ]
        clair += clair_1
        #print ("clair 1 : ", clair_1)
        clair_2 = alphabet_2[carte_1_x * 4 + carte_2_y ]
        #print ("clair 2 : ", clair_2)
        clair += clair_2
    
    ligne_CT = ""
    ligne_clair = ""
    for i in range (0,long,4):
        ligne_CT += texte[i:i+4] + " "
    m=len(ligne_CT)
        
    #print(ligne_CT)   
        
    for j in range (0, long, 2):
        ligne_clair += clair[j:j+2] + "   "
    #print(ligne_clair)    
    #print(clair)
    #print ("l :",len(texte))
    for k in range (0,m,120):
        print(ligne_CT[k: k+120],"\n", ligne_clair[k: k+120], "\n" )
    
    

    7CXS 3H6S 7CKS XDAS 2CKS 8D4S 9C2S 7DXS 3D9S 7C2S 6HJS 9C2S 3D7S 8CQH ACQS AH5S 9DJH 7D3S 8D5S 7CQH 3D8S 2CKS AH3S 7CXS
    re po rt .n t. em ee t. ng be t. ee n. .. rl es .. .k en .. n. t. e. re

    6DJH XCJH XC9S 8DAS XCAS 8CJH 8D5S ACQH JD5S JC2S XCXS XC9S ACJH JCKH 2CKS 8D4S 8D4S 7C2S QDKS 5CJH 2CKS 2D3S 9CQS QC3S
    .. .e nt .n .t .e en .. .n ge ve nt .. .r t. em em be rs .. t. e. ur ..

    5CJH 2CKS 9C5S 6DXS 9D6S 6HKS 2H2S 8DKS XCQH 7DXS XDAS 2CKS AH3S 7CXS 6DJH XCJH XC9S JC4S 9C2S 8CXS 9DKH KCQS 5D3S 7C6S
    .. t. et r. n. t. fo un .. t. .n t. e. re .. .e nt gr ee te .m r. .. .e

    …………………..

    The original message is page 15 #115070

    #115307
    upsidedown
    Participant

    @ByteInBits are you using a version of Python older than 3.8? The := operator was introduced then. Does the error message tell you the position of the bad syntax?

    #115356
    Puzzling_Pelican
    Participant

    @AES_of_spades, I would agree with @Crackerjack_404’s point, once you have built up the basics (a 9 in CS definitely satisfies this, well done!), projects are the way to go. If you can find a project that stretches you, plan out even more features you can build on top of it as you go, and keep the project going for several months, you can learn a lot while having a ton of fun.
    Additionally, another way to build confidence is speed coding style challenges like OUCC (now renamed Bebras coding) or my school proudly host the PCTC, both of which you can find some past challenges for to have a go at.
    Try not to admire code as unreadable as what this small competition in the forums has produced, the only good that comes from such code it the sudden realization after a point of just how important readability is and actually focusing on this in code.

    @upsidedown, amazing explanation, I couldn’t have done better, thanks!

    #115369
    _madness_
    Participant

    @F6EXB_the_frenchy
    Add some hill-climbing, and you will have it.

Viewing 7 posts - 271 through 277 (of 277 total)
  • You must be logged in to reply to this topic.
Report a problem