More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
post
page
Python IDE Dashboard

Javascript: Alert, prompt or confirm?

javascript-popupJavascript popup box are extremely useful when you start coding in Javascript. They enable you to write basic programs based on the Input/Process/Output very easily.

alert(“…”)


An alert box is an easy approach in javascript to display a message to the end user. It can be used as a form of output (equivalent to a print() statement in Python). The main drawback (or benefit?) of an alert box is that the Javascript code will pause until the user closes the popup box.

alert("Hello world!");
Try this code!

prompt(“…”)


An prompt box is an easy approach in javascript to retrieve a user input from the end user. It can be used as a form of input (equivalent to a input() statement in Python). The value returned by a prompt() function can then be stored in a variable.

var name;
name = prompt("What's your name?");
alert("Hello " + name + "!");
Try this code!

confirm(“…”)


A confirm box is used when you need the user to verify or accept something.
When a confirm box pops up, the user has to click either “OK” or “Cancel” to proceed.
If the user clicks “OK”, the box returns true. If the user clicks “Cancel”, the box returns false.

var play = confirm("Would you like the play a game of heads or tails?");
if (play==true) {
   if (Math.floor(Math.random() * 2) == 0) {
      alert("Heads!");
   } else {
      alert("Tails!");
   }
} else {
   alert("Good bye then!");
}
Try this code!

Your Turn


Use the codepen below to create pure Javascript games or programs based on the input/process/output model.
You can look at the following challenges to implement these using Javascript.

See the Pen
Heads or Tails
by 101 Computing (@101Computing)
on CodePen.

Network Design Tasks

In this post we will investigate the different components needed to set up a network. We will investigate specific customer requirements to create suitable network designs.

You will use our online network design tool to create these designs using the relevant hardware and cables.

Before attempting this task, you may want to read more about the different network components and their purpose.

Customer ACustomer BCustomer C
recruitment-agency

Customer A


Customer A is a recruitment agency that employs 7 members of staff working in a small office.

  1. They would like to have enough desktops for each employee to be able to work at the same time.
  2. They would like all files to be stored on a central server.
  3. Each employee is provided with a laptop or smartphone which they will need to connect to the network using a wireless connection.
  4. They should be able to access the internet.
  5. They want to have a secure connection that prevents unauthorised requests entering the network.
Design Your Own Network Online

Video Tutorial



network-web-design

Customer B


Customer B is web design agency that employs 5 members of staff working in a small office.

  1. They would like to have enough desktops for each employee to be able to work at the same time.
  2. They would like to connect a printer to the network.
  3. They would like all files to be stored on a central server.
  4. They should be able to access the internet.
  5. They would like to set up email accounts using their own email server.
  6. They design webpages for their customers and would like to host them on their own servers.
  7. They would like a centralised solution to back up all their files.
  8. They need a secure connection that prevents unauthorised access to the network.
Design Your Own Network Online
primary-school

Customer C


Customer C is a primary school that has 3 IT classrooms with 8 desktop computers per room.

  1. They would like all desktops to be connected in a local area network.
  2. They would also like the 5 teachers to have wireless access to the LAN using their own laptops.
  3. They would like all students’ files to be stored on a central server.
  4. They would like a centralised backup solution to backup all students files every night.
  5. All desktops and laptops should be able to access the internet.
  6. They would like to have a printer in each IT room and a centralised approach to organise printer credits and print queues.
  7. They would like to set up email accounts using their own email server.
  8. They would like to apply specific education filters to restrict students access to specific webpages.
  9. They would like to improve the performance of the network by temporary caching webpages that have been accessed by students.
  10. They need a secure connection that prevents unauthorised access to the network.
Design Your Own Network Online
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with:

Divisibility Rules

For this challenge we will investigate a range of algorithms used to apply some of the most common divisibility rules. We will first focus on the divisibility rule of 3 to introduce the concept of recursion.

A divisibility rule is a shorthand way of determining whether a given integer is divisible by a fixed divisor without performing the division, usually by examining its digits

Divisibility rule

So, for this challenge we will focus on implementing the divisibility rules using some python scripts without using the DIV (//) or MOD (%) operators. In reality, these operators would be a more elegant way of checking if a number is divisible by another number.

Divisibility Rule for 2

A number is divisible by 2 if its last digit is a multiple of 2. (e.g. 0,2,4,6,8)

Divisibility rule for 2

Let’s look at the following example: is 378 divisible by 2? Yes because its last digit, 8 is a multiple of 2.

Let’s write a Python a function to implement this divisibility rule for 2:

Divisibility Rule for 3

A number is divisible by 3 if the sum of all its digits is divisible by 3.

Divisibility rule for 3

Let’s look at the following example: is 378 divisible by 3?
divisibility-rule-for-3

Our aim is to write a function that takes a number as a parameter and returns whether this number is divisible by 3. To implement this function we will use a recursive function (A function with a call to itself).

Your Task


Your task is to adapt the above algorithms to implement the divisibility rules for 4,5,6.

A number is divisible by 4, if the number formed by its last two digits is divisible by 4.

Divisibility rule for 4

A number is divisible by 5, if its last digit is either a 0 or a 5.

Divisibility rule for 5

A number is divisible by 6, if it is divisible by 3 and by 2.

Divisibility rule for 6

Extension Task: Divisibility rule for 7


Apply a recursive method to find out is a number is divisible by 7. First you will need to read more about the divisibility rule for 7 on this wikipedia page.

Tagged with:

Number 2520?

number-2520Did you know that 2520 is the smallest number exactly divisible by all integers from 1 to 10.

The aim of this challenge is to write a python script to work out this number from its definition.

Note that a number (a) is exactly divisible (whole division) by another number (b) if the remainder of divising a per b is equal to 0.

In pseudo code:

a = INPUT("Type a whole number (integer)")
a = INPUT("Type another whole number (integer)")
IF (a MOD b) == 0 THEN
   OUTPUT(a + " is exactly divisible by " + b)
ELSE
  OUTPUT(a + " is not exactly divisible by " + b)
END IF

In Python the MOD operator (remainder) is %.

a = int(input("Type a whole number (integer)"))
b = int(input("Type another whole number (integer)"))
if (a % b) == 0:
   print(str(a) + " is exactly divisible by " + str(b))
else:
  print(str(a) + " is not exactly divisible by " + str(b))

We are going to use this operator in our code to find out the smallest number exactly divisible by all integers from 1 to 10.

Note that we know, per definition, that this number will have to be greater or equal to 10. So, using an iterative approach (in this case, a while loop) we will test every number from 10, one at a time up until we find a number that is divisible by all the numbers from 1 to 10.

Flowchart


Here is the flowchart of our algorithm:
number-2520-flowchart

Python Code


You can use the above flowchart to recreate the Python code in the trinket window below:

Tagged with:

Vatsyayana cipher

The Vatsyayana cipher is a simple substitution cipher where the 26 letters of the alphabet are organised into 13 pairs of characters. These pairs are then used to encrypt the text by direct substitution of the letters in the pairs.

Vatsyayana-substitution-cipher

Pairs:

A/E B/T C/J D/N
F/W G/S H/K I/Z
L/V M/R O/Y P/U
Q/X

With the above key, all “A” letters in the plain text will be encoded to an “E” whereas all letters “E” will be replaced with an “A”.

This type of cipher is a form of symmetric encryption as the same key can be used to both encrypt and decrypt a message.

You can generate your own encryption keys and encrypt your own messages using our online mono-alphabetic substitution engine:

Frequency Analysis


One approach used to help decrypt a Vatsyayana substitution cipher is to use a frequency analysis based on counting the number of occurrence of each letter to help identify the most recurrent letters. (e.g. In the English language, letters E, T, A and O).

Tagged with: ,

Caesar Shift (Substitution Cipher)

A Caesar Shift cipher is a type of mono-alphabetic substitution cipher where each letter of the plain text is shifted a fixed number of places down the alphabet. For example, with a shift of 1, letter A would be replaced by letter B, letter B would be replaced by letter C, and so on. This type of substitution Cipher is named after Julius Caesar, who used it to communicate with his generals.

Key +5
Plain text alphabet:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
shift-5-places
Cipher text alphabet: F G H I J K L M N O P Q R S T U V W X Y Z A B C D E

This type of cipher is a form of symmetric encryption as the same key can be used to both encrypt and decrypt a message. (e.g. If a message is encrypted with a key of +5, it can be decrypted with a key of -5).

A cipher wheel is a tool used to help decipher a message encrypted using the Caesar cipher:

You can generate your own encryption keys and encrypt your own messages using our online Caesar Shift substitution engine:

Frequency Analysis


One approach used to help decrypt a Caesar shift substitution cipher is to use a frequency analysis based on counting the number of occurrence of each letter to help identify the most recurrent letters. (e.g. In the English language, letters E, T and A).

Your Task:


Complete a frequency analysis to decrypt the following ciphers.
Cipher #1Cipher #2Cipher #3
“ZE KYV KFNE NYVIV Z NRJ SFIE
CZMVU R DRE NYF JRZCVU KF JVR
REU YV KFCU LJ FW YZJ CZWV
ZE KYV CREU FW JLSDRIZEVJ
JF NV JRZCVU LG KF KYV JLE
‘KZC NV WFLEU R JVR FW XIVVE
REU NV CZMVU SVEVRKY KYV NRMVJ
ZE FLI PVCCFN JLSDRIZEV
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
REU FLI WIZVEUJ RIV RCC RSFRIU
DREP DFIV FW KYVD CZMV EVOK UFFI
REU KYV SREU SVXZEJ KF GCRP
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
(WLCC JGVVU RYVRU DI. GRIBVI, WLCC JGVVU RYVRU
WLCC JGVVU RYVRU ZK ZJ, JVIXVREK
RTKZFE JKRKZFE, RTKZFE JKRKZFE
RPV, RPV, JZI, WZIV
TRGKRZE, TRGKRZE)
RJ NV CZMV R CZWV FW VRJV
VMVIPFEV FW LJ YRJ RCC NV EVVU (YRJ RCC NV EVVU)
JBP FW SCLV (JBP FW SCLV) REU JVR FW XIVVE (REU JVR FW XIVVE)
ZE FLI PVCCFN JLSDRIZEV (ZE FLI PVCCFN, JLSDRIZEV, YR YR)
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV”

View Hint
A song by The Beattles
“WAOUWBS HVSFS’G BC QCIBHFWSG
WH WGB’H VOFR HC RC
BCHVWBU HC YWZZ CF RWS TCF
OBR BC FSZWUWCB, HCC
WAOUWBS OZZ HVS DSCDZS
ZWJWBU ZWTS WB DSOQS
MCI, MCI AOM GOM W’A O RFSOASF
PIH W’A BCH HVS CBZM CBS
W VCDS GCASROM MCI KWZZ XCWB IG
OBR HVS KCFZR KWZZ PS OG CBS
WAOUWBS BC DCGGSGGWCBG
W KCBRSF WT MCI QOB
BC BSSR TCF UFSSR CF VIBUSF
O PFCHVSFVCCR CT AOB
WAOUWBS OZZ HVS DSCDZS
GVOFWBU OZZ HVS KCFZR
MCI, MCI AOM GOM W’A O RFSOASF
PIH W’A BCH HVS CBZM CBS
W VCDS GCASROM MCI KWZZ XCWB IG
OBR HVS KCFZR KWZZ ZWJS OG CBS”

View Hint
A song by John Lennon
“SBRL ZRFDHSRLY OHZ YLABYULK AV OPZ OVTL WSHULA VM AHAVVPUL PU HU HAALTWA AV YLZJBL OPZ MYPLUK OHU ZVSV MYVT AOL JSBAJOLZ VM AOL CPSL NHUNZALY QHIIH AOL OBAA.

SPAASL KVLZ SBRL RUVD AOHA AOL NHSHJAPJ LTWPYL OHZ ZLJYLASF ILNBU JVUZAYBJAPVU VU H ULD HYTVYLK ZWHJL ZAHAPVU LCLU TVYL WVDLYMBS AOHU AOL MPYZA KYLHKLK KLHAO ZAHY.

DOLU JVTWSLALK, AOPZ BSAPTHAL DLHWVU DPSS ZWLSS JLYAHPU KVVT MVY AOL ZTHSS IHUK VM YLILSZ ZAYBNNSPUN AV YLZAVYL MYLLKVT AV AOL NHSHEF…”


View Hint
Star wars opening crawl
Tagged with: ,

Frequency Analysis

In cryptography, frequency analysis is the study of the frequency of letters or groups of letters in a ciphertext. The method is used as an aid to breaking substitution ciphers (e.g. mono-alphabetic substitution cipher, Caesar shift cipher, Vatsyayana cipher).

Frequency analysis consists of counting the occurrence of each letter in a text. Frequency analysis is based on the fact that, in any given piece of text, certain letters and combinations of letters occur with varying frequencies. For instance, given a section of English language, letters E, T, A and O are the most common, while letters Z, Q and X are not as frequently used.

The following chart shows the frequency of each letter of the alphabet for the English language:
frequency-analysis-english-language

We can assume that most samples of text written in English would have a similar distribution of letters. However this is only true if the sample of text is long enough. A very short text may lead to a significantly different distribution.

When trying to decrypt a cipher text based on a substitution cipher, we can use a frequency analysis to help identify the most recurring letters in a cipher text and hence make hypothesis of what these letters have been encoded as (e.g. E, T, A, O, etc). This will help us decrypt some of the letters in the text. We can then recognise patterns/words in the partly decoded text to identify more substitutions.

You can perform a frequency analysis on the following text to try to decrypt this text step by step:

Your Task:


Complete a frequency analysis to decrypt the following ciphers.
Cipher #1Cipher #2Cipher #3Cipher #4Cipher #5Cipher #6Cipher #7Cipher #8
“DJ DK C QLXDWI WF SDGDU PCX. XLRLU KQCSLKBDQK, KJXDHDET FXWZ C BDIILE RCKL, BCGL PWE JBLDX FDXKJ GDSJWXO CTCDEKJ JBL LGDU TCUCSJDS LZQDXL. IYXDET JBL RCJJUL, XLRLU KQDLK ZCECTLI JW KJLCU KLSXLJ QUCEK JW JBL LZQDXL’K YUJDZCJL PLCQWE, JBL ILCJB KJCX, CE CXZWXLI KQCSL KJCJDWE PDJB LEWYTB QWPLX JW ILKJXWO CE LEJDXL QUCELJ. QYXKYLI RO JBL LZQDXL’K KDEDKJLX CTLEJK, QXDESLKK ULDC XCSLK BWZL CRWCXI BLX KJCXKBDQ, SYKJWIDCE WF JBL KJWULE QUCEK JBCJ SCE KCGL BLX QLWQUL CEI XLKJWXL FXLLIWZ JW JBL TCUCVO…”

View Hint
Star wars opening crawl
“JVUI LUMNCJUIG KCL GIXVGEIS XO KPL KOYI AJCEIX OQ XCXOOPEI PE CE CXXIYAX XO GILWVI KPL QGPIES KCE LOJO QGOY XKI WJVXWKIL OQ XKI DPJI TCETLXIG BCHHC XKI KVXX.
JPXXJI SOIL JVUI UEON XKCX XKI TCJCWXPW IYAPGI KCL LIWGIXJM HITVE WOELXGVWXPOE OE C EIN CGYOGIS LACWI LXCXPOE IDIE YOGI AONIGQVJ XKCE XKI QPGLX SGICSIS SICXK LXCG.
NKIE WOYAJIXIS, XKPL VJXPYCXI NICAOE NPJJ LAIJJ WIGXCPE SOOY QOG XKI LYCJJ HCES OQ GIHIJL LXGVTTJPET XO GILXOGI QGIISOY XO XKI TCJCZM…”

View Hint
Star wars opening crawl
“OK OH R WRFD KOIS QPF KNS FSTSJJOPX. RJKNPAGN KNS WSRKN HKRF NRH TSSX WSHKFPCSW, OIBSFORJ KFPPBH NRYS WFOYSX KNS FSTSJ QPFMSH QFPI KNSOF NOWWSX TRHS RXW BAFHASW KNSI RMFPHH KNS GRJREC.
SYRWOXG KNS WFSRWSW OIBSFORJ HKRFQJSSK, R GFPAB PQ QFSSWPI QOGNKSFH JSW TC JADS HDCVRJDSF NRH SHKRTJOHNSW R XSV HSMFSK TRHS PX KNS FSIPKS OMS VPFJW PQ NPKN.
KNS SYOJ JPFW WRFKN YRWSF, PTHSHHSW VOKN QOXWOXG CPAXG HDCVRJDSF, NRH WOHBRKMNSW KNPAHRXWH PQ FSIPKS BFPTSH OXKP KNS QRF FSRMNSH PQ HBRMS…”

View Hint
Star wars opening crawl
“ZRTFT IH PQFTHZ IQ ZRT XBGBOZIO HTQBZT. HTWTFBG ZRLPHBQV HLGBF HYHZTSH RBWT VTOGBFTV ZRTIF IQZTQZILQH ZL GTBWT ZRT FTEPKGIO.
ZRIH HTEBFBZIHZ SLWTSTQZ, PQVTF ZRT GTBVTFHRIE LD ZRT SYHZTFILPH OLPQZ VLLAP, RBH SBVT IZ VIDDIOPGZ DLF ZRT GISIZTV QPSKTF LD CTVI AQIXRZH ZL SBIQZBIQ ETBOT BQV LFVTF IQ ZRT XBGBJY.
HTQBZLF BSIVBGB, ZRT DLFSTF NPTTQ LD QBKLL, IH FTZPFQIQX ZL ZRT XBGBOZIO HTQBZT ZL WLZT LQ ZRT OFIZIOBG IHHPT LD OFTBZIQX BQ BFSY LD ZRT FTEPKGIO ZL BHHIHZ ZRT LWTFMRTGSTV CTVI…”

View Hint
Star wars opening crawl
“FX IWBBJX PB NB PB PWX GBBD. VSP FWO, JBGX JRO, PWX GBBD? FWO IWBBJX PWUJ RJ BSA NBRK? RDL PWXO GRO FXKK RJM FWO IKUGV PWX WUNWXJP GBSDPRUD? FWO, 35 OXRAJ RNB, EKO PWX RPKRDPUI? FWO LBXJ AUIX CKRO PXQRJ? FX IWBBJX PB NB PB PWX GBBD UD PWUJ LXIRLX RDL LB PWX BPWXA PWUDNJ, DBP VXIRSJX PWXO RAX XRJO, VSP VXIRSJX PWXO RAX WRAL, VXIRSJX PWRP NBRK FUKK JXATX PB BANRDUZX RDL GXRJSAX PWX VXJP BE BSA XDXANUXJ RDL JMUKKJ, VXIRSJX PWRP IWRKKXDNX UJ BDX PWRP FX RAX FUKKUDN PB RIIXCP, BDX FX RAX SDFUKKUDN PB CBJPCBDX, RDL BDX FWUIW FX UDPXDL PB FUD, RDL PWX BPWXAJ, PBB.”

View Hint
Destination Moon – Most frequent letters: letter “E” and letter “O”
“ZE KYV KFNE NYVIV Z NRJ SFIE
CZMVU R DRE NYF JRZCVU KF JVR
REU YV KFCU LJ FW YZJ CZWV
ZE KYV CREU FW JLSDRIZEVJ
JF NV JRZCVU LG KF KYV JLE
‘KZC NV WFLEU R JVR FW XIVVE
REU NV CZMVU SVEVRKY KYV NRMVJ
ZE FLI PVCCFN JLSDRIZEV
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
REU FLI WIZVEUJ RIV RCC RSFRIU
DREP DFIV FW KYVD CZMV EVOK UFFI
REU KYV SREU SVXZEJ KF GCRP
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
(WLCC JGVVU RYVRU DI. GRIBVI, WLCC JGVVU RYVRU
WLCC JGVVU RYVRU ZK ZJ, JVIXVREK
RTKZFE JKRKZFE, RTKZFE JKRKZFE
RPV, RPV, JZI, WZIV
TRGKRZE, TRGKRZE)
RJ NV CZMV R CZWV FW VRJV
VMVIPFEV FW LJ YRJ RCC NV EVVU (YRJ RCC NV EVVU)
JBP FW SCLV (JBP FW SCLV) REU JVR FW XIVVE (REU JVR FW XIVVE)
ZE FLI PVCCFN JLSDRIZEV (ZE FLI PVCCFN, JLSDRIZEV, YR YR)
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV
NV RCC CZMV ZE R PVCCFN JLSDRIZEV
PVCCFN JLSDRIZEV, PVCCFN JLSDRIZEV”

View Hint
A song by The Beattles
“WAOUWBS HVSFS’G BC QCIBHFWSG
WH WGB’H VOFR HC RC
BCHVWBU HC YWZZ CF RWS TCF
OBR BC FSZWUWCB, HCC
WAOUWBS OZZ HVS DSCDZS
ZWJWBU ZWTS WB DSOQS
MCI, MCI AOM GOM W’A O RFSOASF
PIH W’A BCH HVS CBZM CBS
W VCDS GCASROM MCI KWZZ XCWB IG
OBR HVS KCFZR KWZZ PS OG CBS
WAOUWBS BC DCGGSGGWCBG
W KCBRSF WT MCI QOB
BC BSSR TCF UFSSR CF VIBUSF
O PFCHVSFVCCR CT AOB
WAOUWBS OZZ HVS DSCDZS
GVOFWBU OZZ HVS KCFZR
MCI, MCI AOM GOM W’A O RFSOASF
PIH W’A BCH HVS CBZM CBS
W VCDS GCASROM MCI KWZZ XCWB IG
OBR HVS KCFZR KWZZ ZWJS OG CBS”

View Hint
A song by John Lennon
“SBRL ZRFDHSRLY OHZ YLABYULK AV OPZ OVTL WSHULA VM AHAVVPUL PU HU HAALTWA AV YLZJBL OPZ MYPLUK OHU ZVSV MYVT AOL JSBAJOLZ VM AOL CPSL NHUNZALY QHIIH AOL OBAA.

SPAASL KVLZ SBRL RUVD AOHA AOL NHSHJAPJ LTWPYL OHZ ZLJYLASF ILNBU JVUZAYBJAPVU VU H ULD HYTVYLK ZWHJL ZAHAPVU LCLU TVYL WVDLYMBS AOHU AOL MPYZA KYLHKLK KLHAO ZAHY.

DOLU JVTWSLALK, AOPZ BSAPTHAL DLHWVU DPSS ZWLSS JLYAHPU KVVT MVY AOL ZTHSS IHUK VM YLILSZ ZAYBNNSPUN AV YLZAVYL MYLLKVT AV AOL NHSHEF…”


View Hint
Star wars opening crawl
Tagged with: ,

Mono-Alphabetic Substitution Cipher

A mono-alphabetic cipher (aka simple substitution cipher) is a substitution cipher where each letter of the plain text is replaced with another letter of the alphabet. It uses a fixed key which consist of the 26 letters of a “shuffled alphabet”.

Plain text alphabet:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Cipher text alphabet (key): M U A L V O Z K R N J X Q D F S H P E B C T I W Y G

With the above key, all “A” letters in the plain text will be encoded to an “M”.

This type of cipher is a form of symmetric encryption as the same key can be used to both encrypt and decrypt a message.

You can generate your own encryption keys and encrypt your own messages using our online mono-alphabetic substitution engine:

Frequency Analysis


One approach used to help decrypt a mono-alphabetic substitution cipher is to use a frequency analysis based on counting the number of occurrence of each letter to help identify the most recurrent letters. (e.g. In the English language, letters E, T and A).

Your Task:


Complete a frequency analysis to decrypt the following ciphers.
Cipher #1Cipher #2Cipher #3Cipher #4Cipher #5
“DJ DK C QLXDWI WF SDGDU PCX. XLRLU KQCSLKBDQK, KJXDHDET FXWZ C BDIILE RCKL, BCGL PWE JBLDX FDXKJ GDSJWXO CTCDEKJ JBL LGDU TCUCSJDS LZQDXL. IYXDET JBL RCJJUL, XLRLU KQDLK ZCECTLI JW KJLCU KLSXLJ QUCEK JW JBL LZQDXL’K YUJDZCJL PLCQWE, JBL ILCJB KJCX, CE CXZWXLI KQCSL KJCJDWE PDJB LEWYTB QWPLX JW ILKJXWO CE LEJDXL QUCELJ. QYXKYLI RO JBL LZQDXL’K KDEDKJLX CTLEJK, QXDESLKK ULDC XCSLK BWZL CRWCXI BLX KJCXKBDQ, SYKJWIDCE WF JBL KJWULE QUCEK JBCJ SCE KCGL BLX QLWQUL CEI XLKJWXL FXLLIWZ JW JBL TCUCVO…”

View Hint
Star wars opening crawl
“Q WNN JFNNW XP TFNNS, FNR FXWNW JXX
Q WNN JYNA GHXXA PXF AN DSR KXB
DSR Q JYQSE JX AKWNHP OYDJ D OXSRNFPBH OXFHR
Q WNN WEQNW XP GHBN DSR LHXBRW XP OYQJN
JYN GFQTYJ GHNWWNR RDK, JYN RDFE WDLFNR SQTYJ
DSR Q JYQSE JX AKWNHP OYDJ D OXSRNFPBH OXFHR
JYN LXHXFW XP JYN FDQSGXO WX ZFNJJK QS JYN WEK
DFN DHWX XS JYN PDLNW XP ZNXZHN TXQST GK
Q WNN PFQNSRW WYDEQST YDSRW WDKQST YXO RX KXB RX
JYNK’FN FNDHHK WDKQST Q HXUN KXB
Q YNDF GDGQNW LFKQST, Q ODJLY JYNA TFXO
JYNK’HH HNDFS ABLY AXFN JYDS Q’HH SNUNF ESXO
DSR Q JYQSE JX AKWNHP OYDJ D OXSRNFPBH OXFHR
KNW Q JYQSE JX AKWNHP OYDJ D OXSRNFPBH OXFHR”

View Hint
A song by Louis Armstrong
“IZRN P SPNA QWBRXS PN DPQRB ES DHEJVXR, QEDZRH QUHW GEQRB DE QR
BLRUOPNY IEHAB ES IPBAEQ, XRD PD VR
UNA PN QW ZEJH ES AUHONRBB BZR PB BDUNAPNY HPYZD PN SHEND ES QR
BLRUOPNY IEHAB ES IPBAEQ, XRD PD VR
XRD PD VR, XRD PD VR, XRD PD VR, XRD PD VR
IZPBLRH IEHAB ES IPBAEQ, XRD PD VR
UNA IZRN DZR VHEORN-ZRUHDRA LRELXR XPCPNY PN DZR IEHXA UYHRR
DZRHR IPXX VR UN UNBIRH, XRD PD VR
SEH DZEJYZ DZRW QUW VR LUHDRA, DZRHR PB BDPXX U GZUNGR DZUD DZRW IPXX BRR
DZRHR IPXX VR UN UNBIRH, XRD PD VR
XRD PD VR, XRD PD VR, XRD PD VR, XRD PD VR
WRUZ, DZRHR IPXX VR UN UNBIRH, XRD PD VR
XRD PD VR, XRD PD VR, XRD PD VR, XRD PD VR
IZPBLRH IEHAB ES IPBAEQ, XRD PD VR
XRD PD VR, XRD PD VR, XRD PD VR, WRUZ, XRD PD VR
IZPBLRH IEHAB ES IPBAEQ, XRD PD VR
UNA IZRN DZR NPYZD PB GXEJAW DZRHR PB BDPXX U XPYZD DZUD BZPNRB EN QR
BZPNR JNDPX DEQEHHEI, XRD PD VR
P IUOR JL DE DZR BEJNA ES QJBPG, QEDZRH QUHW GEQRB DE QR
BLRUOPNY IEHAB ES IPBAEQ, XRD PD VR
XRD PD VR, XRD PD VR, XRD PD VR, WRUZ, XRD PD VR
DZRHR IPXX VR UN UNBIRH, XRD PD VR
XRD PD VR, XRD PD VR, XRD PD VR, WRUZ, XRD PD VR
DZRHR IPXX VR UN UNBIRH, XRD PD VR
XRD PD VR, XRD PD VR, XRD PD VR, WRUZ, XRD PD VR
IZPBLRH IEHAB ES IPBAEQ, XRD PD VR”

View Hint
A song by The Beattles
“ZRTFT IH PQFTHZ IQ ZRT XBGBOZIO HTQBZT. HTWTFBG ZRLPHBQV HLGBF HYHZTSH RBWT VTOGBFTV ZRTIF IQZTQZILQH ZL GTBWT ZRT FTEPKGIO.
ZRIH HTEBFBZIHZ SLWTSTQZ, PQVTF ZRT GTBVTFHRIE LD ZRT SYHZTFILPH OLPQZ VLLAP, RBH SBVT IZ VIDDIOPGZ DLF ZRT GISIZTV QPSKTF LD CTVI AQIXRZH ZL SBIQZBIQ ETBOT BQV LFVTF IQ ZRT XBGBJY.
HTQBZLF BSIVBGB, ZRT DLFSTF NPTTQ LD QBKLL, IH FTZPFQIQX ZL ZRT XBGBOZIO HTQBZT ZL WLZT LQ ZRT OFIZIOBG IHHPT LD OFTBZIQX BQ BFSY LD ZRT FTEPKGIO ZL BHHIHZ ZRT LWTFMRTGSTV CTVI…”

View Hint
Star wars opening crawl
“FX IWBBJX PB NB PB PWX GBBD. VSP FWO, JBGX JRO, PWX GBBD? FWO IWBBJX PWUJ RJ BSA NBRK? RDL PWXO GRO FXKK RJM FWO IKUGV PWX WUNWXJP GBSDPRUD? FWO, 35 OXRAJ RNB, EKO PWX RPKRDPUI? FWO LBXJ AUIX CKRO PXQRJ? FX IWBBJX PB NB PB PWX GBBD UD PWUJ LXIRLX RDL LB PWX BPWXA PWUDNJ, DBP VXIRSJX PWXO RAX XRJO, VSP VXIRSJX PWXO RAX WRAL, VXIRSJX PWRP NBRK FUKK JXATX PB BANRDUZX RDL GXRJSAX PWX VXJP BE BSA XDXANUXJ RDL JMUKKJ, VXIRSJX PWRP IWRKKXDNX UJ BDX PWRP FX RAX FUKKUDN PB RIIXCP, BDX FX RAX SDFUKKUDN PB CBJPCBDX, RDL BDX FWUIW FX UDPXDL PB FUD, RDL PWX BPWXAJ, PBB.”

View Hint
Destination Moon – Most frequent letter: letter “O”
Tagged with: ,

Shuffling a 2D Array

For this challenge we will investigate how to create a 2D array to store the value from 1 to 100 in a 10×10 array. We will then write an algorithm to shuffle the content of this array.
2d-array-1-100
See the code below to see how the array can be initialised to contain all numbers from 1 to 100 and how it is then displayed on screen.

Your Challenge


The aim of this challenge will is add a function to the code above to shuffle all 100 values inside the array:
shuffling-2d-array

Solution


Check the following flowchart for a solution that:

  • Accesses each value of the array one by one (using two nested loops),
  • Swaps each value: it swaps the value with another value of the array at a random position.

flowchart-shuffling-2d-array

Tagged with: ,

Shuffling Algorithm

Our aim is to implement a shuffling algorithm to shuffle a deck of playing cards.

To do so, we will use a list called deck to store the 52 cards of the deck as follows:

deck = ["Ace of hearts","2 of hearts","3 of hearts","4 of hearts","5 of hearts","6 of hearts","7 of hearts","8 of hearts","9 of hearts","10 of hearts","Jack of hearts","Queen of hearts","King of hearts","Ace of diamonds","2 of diamonds","3 of diamonds","4 of diamonds","5 of diamonds","6 of diamonds","7 of diamonds","8 of diamonds","9 of diamonds","10 of diamonds","Jack of diamonds","Queen of diamonds","King of diamonds","Ace of clubs","2 of clubs","3 of clubs","4 of clubs","5 of clubs","6 of clubs","7 of clubs","8 of clubs","9 of clubs","10 of clubs","Jack of clubs","Queen of clubs","King of clubs","Ace of spades","2 of spades","3 of spades","4 of spades","5 of spades","6 of spades","7 of spades","8 of spades","9 of spades","10 of spades","Jack of spades","Queen of spades","King of spades"]

Even though the random library already has a shuffle() function to shuffle the content of a list, we will ignore this function and create our own algorithm to shuffle the content of our deck of cards.

We will use the following algorithm to shuffle the deck:
flowchart-shuffling-deck-of-cards

Python Code


You can complete the Python code below to implement this algorithm.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: ,