# Section B Introduction

This section will ask you questions that you will have to find programming solutions to. The past exam papers have always provided a strict program specification in the form of variable names and pseudocode. It is very likely that a problem will be set around the theme of cryptography but different to the skeleton code in some way. You should be able to interpret pseudocode, structured english, structure charts, stepwise refinement tables and decision tables. Any of these techniques could be used to communicate an algorithm to be coded.

## Practice questions

Obviously all the past papers from AQA have good section B questions that you should attempt. Here are some around this year's theme...

### Numeric Caesar Cipher

(a) Write a program that encrypts a number sequence using the same principle as the Caesar Cipher. (b) Test your program using a key= 6 and the number sequence 0123456789

```OUTPUT "enter a number to encode"
INPUT plainNum
OUTPUT "enter a key"
INPUT Key
For i = 0 to (length of plainNum -1)
codedNum <-- codedNum & (VALUE(PlainNum(i)) + Key) Mod 10
Next
OUTPUT codedNum
```

```    Sub Main()
Dim plainNum, codedNum As String
Dim Key As Integer
Console.WriteLine("enter a number to encode")
Console.WriteLine("enter a key")
For i = 0 To (plainNum.Length - 1)
codedNum = codedNum & ((Val(plainNum(i)) + Key) Mod 10)
'Val is a bit of a cheat... subtracting 48 from the ascii code converts a character in the range 48-58 to its integer value
'codedNum = codedNum & ((Asc(plainNum(i)) - 48 + Key) Mod 10) ' this line is a nicer way to solve it, althrough both only cope with number method specified
'Obviously it is irrelevant which way is nicer, you MUST use the specified algorithm
Next
Console.WriteLine(codedNum)
End Sub
```

### Character Frequency

Write a program that counts the number of times each character appears in some inputted text. It should output a list of characters with the number of times each appears.

(pseudo-code to follow)

```'solution to follow
Sub Main()
Console.WriteLine("enter a string")
Dim text As String = Console.ReadLine()
Dim textarr(text.Length - 1, 1) As Object
Dim search As Boolean
Dim searchele, newele As Integer
For i = 0 To text.Length - 1
search = False
For j = 0 To text.Length - 1
If text(i) = textarr(j, 0) Then
search = True
searchele = j
End If
Next
If search Then
textarr(searchele, 1) += 1
Else
textarr(newele, 0) = text(i)
textarr(newele, 1) = 1
newele += 1
End If
Next
For i = 0 To newele - 1
Console.WriteLine(textarr(i, 0) & " appears " & textarr(i, 1) & " times")
Next
```'Another solution