Lab Sheet: ARM Assembler Exercises: ROT13 Exercise Version

Total Page:16

File Type:pdf, Size:1020Kb

Lab Sheet: ARM Assembler Exercises: ROT13 Exercise Version Week 7/8 Lab Sheet: ARM Assembler Exercises: ROT13 2020/21 Lab Sheet: ARM Assembler Exercises: ROT13 This lab sheet covers exercises of ARM assembler programming, based on a sequence of screencasts discussing a Caesar cipher (ROT13) implementation. Watch this sequence of screencasts before attempting the exercises below, asking for some small changes to the versions that are online as gitlab projects (marked as ). For making these change to the ARM assembler code and running it, use the online CPUlator. Exercise Version 0: Also handle upper case letters in ROT13 The C code in Version 0 of ROT13 only handles lower case letters. Do the exercise, embedded in the C source code for Version 0, to modify the C function rot13_in_c to also handle upper case letters, as we do in later versions of the Assembler code. Exercise Version 2: Reverse the order of the arguments in calls1.s In ARM Assembler code of Version 2 , the file calls1.s provides a simple template to call a func- tion using C-calling conventions. Modify the code starting from label testme in calls1.s so that the arguments are passed in reverse order. When running the program you should see Arguments: one: 5 ; two: 4; three: 3; four: 2; five: 1 Program is done Exercise Version 3: Return the length of the string as an exit code from the program As a side-effect of the change from v2, the program in Version 3 no longer returns the length of the string, that has been processed, as a result (returned as the value in R0 when reaching the SWI command at the end). In Version 2 this length was accumulated in R4. But in this version R4 is used and modified in the isalph sub-routine. Modify the code in Version 3 so that the length is kept in one register, and make sure that none of the sub-routines modifies this value. Make this modification and run it in in the CPUlator. Set a breakpoint at the SWI command and check whether the value in R4 is the string length. For the default input expect a string length of 43 (hex 0x2b). You don’t need to execute the SWI in the CPUlator itself: this is likely to fail, because the chipset is slightly different from the RPi2. Exercise Version 4: Fix the clobbering of registers R4 and R5 by our sub- routine isalph When executing either Version 3 or Version 4 of the ROT13 code (in rot13_3.s and rot13_4.s), note that the CPUlator gives you warnings about values in registers being “clobbered” by a sub-routine. This is because our sub-routine (isalph) doesn’t adhere to the ARM procedure calling convention. This is mentioned at the end of the screencast for Version 3 of the code. Fix the code in Verison 4 (rot13_4.s), to avoid such clobbering. You’ll need to save the relevant registers on the stack at the beginning of the sub-routine, and restore them at the end of the sub-routine. If 1 Week 7/8 Lab Sheet: ARM Assembler Exercises: ROT13 2020/21 you make the correct changes, the warnings about “clobbering” should disappear in the CPUlator, and, of course, the program should still perform the same ROT13 encryption. Exercise Version 4: Avoid code duplication after the 2 calls to the sub-routine isalph Version 4 of the ROT13 code (in rot13_4.s) calls isalph twice, once to check whether the character in R3 is a lower, then if it is an upper case character. The 6 lines of code after the two calls to isalph are duplicated: CMP R5, #0 BEQ norot2 ADD R3, #ROT @ do the rotation operation on the current char CMP R3, R4 BLE norot2 SUB R3, #26 These lines check whether a wrap-around is necessary to keep the character within the alphabet. This is obviously bad style and a source for bugs if further changes need to be made to the code. Modify the code rot13_4.s of Version 4 , by putting the above six lines into a sub-routine, and eliminating the conditional branch instructions, by using a return value to direct the control flow. Exercise Version 5: Compare the performance of this version with Version 4 The main point of Version 5 is to enhance performance by reducing the number of memory load and store operations. To validate this behaviour, take each of the 2 versions, Version 4 and Version 5, of the code, and run them on the CPUlator. In the window that normally shows the register values, select ’Counters’ as the information to display. For each of the 2 versions take note of the value under ’Simulator core run time (ms)’. This value should be lower for Version 5 compared to Version 4. You may have to use a larger input text, such as the wod3_text in the data area, to achieve high enough runtimes to show a difference. 2.
Recommended publications
  • Simple Substitution and Caesar Ciphers
    Spring 2015 Chris Christensen MAT/CSC 483 Simple Substitution Ciphers The art of writing secret messages – intelligible to those who are in possession of the key and unintelligible to all others – has been studied for centuries. The usefulness of such messages, especially in time of war, is obvious; on the other hand, their solution may be a matter of great importance to those from whom the key is concealed. But the romance connected with the subject, the not uncommon desire to discover a secret, and the implied challenge to the ingenuity of all from who it is hidden have attracted to the subject the attention of many to whom its utility is a matter of indifference. Abraham Sinkov In Mathematical Recreations & Essays By W.W. Rouse Ball and H.S.M. Coxeter, c. 1938 We begin our study of cryptology from the romantic point of view – the point of view of someone who has the “not uncommon desire to discover a secret” and someone who takes up the “implied challenged to the ingenuity” that is tossed down by secret writing. We begin with one of the most common classical ciphers: simple substitution. A simple substitution cipher is a method of concealment that replaces each letter of a plaintext message with another letter. Here is the key to a simple substitution cipher: Plaintext letters: abcdefghijklmnopqrstuvwxyz Ciphertext letters: EKMFLGDQVZNTOWYHXUSPAIBRCJ The key gives the correspondence between a plaintext letter and its replacement ciphertext letter. (It is traditional to use small letters for plaintext and capital letters, or small capital letters, for ciphertext. We will not use small capital letters for ciphertext so that plaintext and ciphertext letters will line up vertically.) Using this key, every plaintext letter a would be replaced by ciphertext E, every plaintext letter e by L, etc.
    [Show full text]
  • Cryptography in Modern World
    Cryptography in Modern World Julius O. Olwenyi, Aby Tino Thomas, Ayad Barsoum* St. Mary’s University, San Antonio, TX (USA) Emails: [email protected], [email protected], [email protected] Abstract — Cryptography and Encryption have been where a letter in plaintext is simply shifted 3 places down used for secure communication. In the modern world, the alphabet [4,5]. cryptography is a very important tool for protecting information in computer systems. With the invention ABCDEFGHIJKLMNOPQRSTUVWXYZ of the World Wide Web or Internet, computer systems are highly interconnected and accessible from DEFGHIJKLMNOPQRSTUVWXYZABC any part of the world. As more systems get interconnected, more threat actors try to gain access The ciphertext of the plaintext “CRYPTOGRAPHY” will to critical information stored on the network. It is the be “FUBSWRJUASLB” in a Caesar cipher. responsibility of data owners or organizations to keep More recent derivative of Caesar cipher is Rot13 this data securely and encryption is the main tool used which shifts 13 places down the alphabet instead of 3. to secure information. In this paper, we will focus on Rot13 was not all about data protection but it was used on different techniques and its modern application of online forums where members could share inappropriate cryptography. language or nasty jokes without necessarily being Keywords: Cryptography, Encryption, Decryption, Data offensive as it will take those interested in those “jokes’ security, Hybrid Encryption to shift characters 13 spaces to read the message and if not interested you do not need to go through the hassle of converting the cipher. I. INTRODUCTION In the 16th century, the French cryptographer Back in the days, cryptography was not all about Blaise de Vigenere [4,5], developed the first hiding messages or secret communication, but in ancient polyalphabetic substitution basically based on Caesar Egypt, where it began; it was carved into the walls of cipher, but more difficult to crack the cipher text.
    [Show full text]
  • The Mathemathics of Secrets.Pdf
    THE MATHEMATICS OF SECRETS THE MATHEMATICS OF SECRETS CRYPTOGRAPHY FROM CAESAR CIPHERS TO DIGITAL ENCRYPTION JOSHUA HOLDEN PRINCETON UNIVERSITY PRESS PRINCETON AND OXFORD Copyright c 2017 by Princeton University Press Published by Princeton University Press, 41 William Street, Princeton, New Jersey 08540 In the United Kingdom: Princeton University Press, 6 Oxford Street, Woodstock, Oxfordshire OX20 1TR press.princeton.edu Jacket image courtesy of Shutterstock; design by Lorraine Betz Doneker All Rights Reserved Library of Congress Cataloging-in-Publication Data Names: Holden, Joshua, 1970– author. Title: The mathematics of secrets : cryptography from Caesar ciphers to digital encryption / Joshua Holden. Description: Princeton : Princeton University Press, [2017] | Includes bibliographical references and index. Identifiers: LCCN 2016014840 | ISBN 9780691141756 (hardcover : alk. paper) Subjects: LCSH: Cryptography—Mathematics. | Ciphers. | Computer security. Classification: LCC Z103 .H664 2017 | DDC 005.8/2—dc23 LC record available at https://lccn.loc.gov/2016014840 British Library Cataloging-in-Publication Data is available This book has been composed in Linux Libertine Printed on acid-free paper. ∞ Printed in the United States of America 13579108642 To Lana and Richard for their love and support CONTENTS Preface xi Acknowledgments xiii Introduction to Ciphers and Substitution 1 1.1 Alice and Bob and Carl and Julius: Terminology and Caesar Cipher 1 1.2 The Key to the Matter: Generalizing the Caesar Cipher 4 1.3 Multiplicative Ciphers 6
    [Show full text]
  • A Hybrid Cryptosystem Based on Vigenère Cipher and Columnar Transposition Cipher
    International Journal of Advanced Technology & Engineering Research (IJATER) www.ijater.com A HYBRID CRYPTOSYSTEM BASED ON VIGENÈRE CIPHER AND COLUMNAR TRANSPOSITION CIPHER Quist-Aphetsi Kester, MIEEE, Lecturer Faculty of Informatics, Ghana Technology University College, PMB 100 Accra North, Ghana Phone Contact +233 209822141 Email: [email protected] / [email protected] graphy that use the same cryptographic keys for both en- Abstract cryption of plaintext and decryption of cipher text. The keys may be identical or there may be a simple transformation to Privacy is one of the key issues addressed by information go between the two keys. The keys, in practice, represent a Security. Through cryptographic encryption methods, one shared secret between two or more parties that can be used can prevent a third party from understanding transmitted raw to maintain a private information link [5]. This requirement data over unsecured channel during signal transmission. The that both parties have access to the secret key is one of the cryptographic methods for enhancing the security of digital main drawbacks of symmetric key encryption, in compari- contents have gained high significance in the current era. son to public-key encryption. Typical examples symmetric Breach of security and misuse of confidential information algorithms are Advanced Encryption Standard (AES), Blow- that has been intercepted by unauthorized parties are key fish, Tripple Data Encryption Standard (3DES) and Serpent problems that information security tries to solve. [6]. This paper sets out to contribute to the general body of Asymmetric or Public key encryption on the other hand is an knowledge in the area of classical cryptography by develop- encryption method where a message encrypted with a reci- ing a new hybrid way of encryption of plaintext.
    [Show full text]
  • Ciphers: Making and Breaking Ralph Morelli Trinity College, Hartford ([email protected])
    Ciphers: Making and Breaking Ralph Morelli Trinity College, Hartford ([email protected]) Smithsonian Institute October 31, 2009 © 2009 Ralph Morelli You are free to reuse and remix this presentation under a creative commons license provided you give credit to the author. http://creativecommons.org/licenses/by/3.0/us/ This presentation was created using Open Office 3.0, free and open source software. http://www.openoffice.org/ Today's Themes • Crypto Cat vs. Mouse: Cryptographer vs. Cryptanalyst • Theoretical security vs. practical security • Implementation, implementation, implementation • The key is security. Part I: Classical Cryptology Basic Terminology Secret Writing Cryptography – making secret messages. Cryptanalysis – breaking secret messages. Cryptology – cryptography and cryptanalysis. Steganography – concealing messages. Cipher Cipher – a method for transforming a message. encipher meet me at six Cipher mmseeieaxtt plaintext ciphertext decipher Code Code – a system in which codewords replace plaintext words or symbols using a codebook. Codebook meet ... 149 me at at 15 146 15 652 six … … me 146 meet 149 … six 652 Types of Cipher Transposition hello Cipher ELOLH (rearrange) 23541 Substitution KHOOR hello Cipher (replace) Plaintext 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 alphabet: D E F G H I J K L M N O P Q R S T U V W X Y Z A B C Earliest Ciphers Herodotus (484-425 B.C.) Persian War (~480 BC), Demaratus' secret message to the Spartans was hidden under the wax on a wooden tablet (steganography).
    [Show full text]
  • Algorithms and Mechanisms Historical Ciphers
    Algorithms and Mechanisms Cryptography is nothing more than a mathematical framework for discussing the implications of various paranoid delusions — Don Alvarez Historical Ciphers Non-standard hieroglyphics, 1900BC Atbash cipher (Old Testament, reversed Hebrew alphabet, 600BC) Caesar cipher: letter = letter + 3 ‘fish’ ‘ilvk’ rot13: Add 13/swap alphabet halves •Usenet convention used to hide possibly offensive jokes •Applying it twice restores the original text Substitution Ciphers Simple substitution cipher: a=p,b=m,c=f,... •Break via letter frequency analysis Polyalphabetic substitution cipher 1. a = p, b = m, c = f, ... 2. a = l, b = t, c = a, ... 3. a = f, b = x, c = p, ... •Break by decomposing into individual alphabets, then solve as simple substitution One-time Pad (1917) Message s e c r e t 18 5 3 17 5 19 OTP +15 8 1 12 19 5 7 13 4 3 24 24 g m d c x x OTP is unbreakable provided •Pad is never reused (VENONA) •Unpredictable random numbers are used (physical sources, e.g. radioactive decay) One-time Pad (ctd) Used by •Russian spies •The Washington-Moscow “hot line” •CIA covert operations Many snake oil algorithms claim unbreakability by claiming to be a OTP •Pseudo-OTPs give pseudo-security Cipher machines attempted to create approximations to OTPs, first mechanically, then electronically Cipher Machines (~1920) 1. Basic component = wired rotor •Simple substitution 2. Step the rotor after each letter •Polyalphabetic substitution, period = 26 Cipher Machines (ctd) 3. Chain multiple rotors Each rotor steps the next one when a full
    [Show full text]
  • Crypyto Documentation Release 0.2.0
    crypyto Documentation Release 0.2.0 Yan Orestes Aug 22, 2018 API Documentation 1 Getting Started 3 1.1 Dependencies...............................................3 1.2 Installing.................................................3 2 Ciphers 5 2.1 Polybius Square.............................................5 2.2 Atbash..................................................6 2.3 Caesar Cipher..............................................7 2.4 ROT13..................................................8 2.5 Affine Cipher...............................................9 2.6 Rail Fence Cipher............................................9 2.7 Keyword Cipher............................................. 10 2.8 Vigenère Cipher............................................. 11 2.9 Beaufort Cipher............................................. 12 2.10 Gronsfeld Cipher............................................. 13 3 Substitution Alphabets 15 3.1 Morse Code............................................... 15 3.2 Binary Translation............................................ 16 3.3 Pigpen Cipher.............................................. 16 3.4 Templar Cipher.............................................. 18 3.5 Betamaze Alphabet............................................ 19 Python Module Index 21 i ii crypyto Documentation, Release 0.2.0 crypyto is a Python package that provides a set of cryptographic tools with simple use to your applications. API Documentation 1 crypyto Documentation, Release 0.2.0 2 API Documentation CHAPTER 1 Getting Started These instructions
    [Show full text]
  • Simple Ciphers
    Swenson c02.tex V3 - 01/29/2008 1:07pm Page 1 CHAPTER 1 Simple Ciphers As long as there has been communication, there has been an interest in keeping some of this information confidential. As written messages became more widespread, especially over distances, people learned how susceptible this particular medium is to being somehow compromised: The messages can be easily intercepted, read, destroyed, or modified. Some protective methods were employed, such as sealing a message with a wax seal, which serves to show the communicating parties that the message is genuine and had not been intercepted. This, however, did nothing to actually conceal the contents. This chapter explores some of the simplest methods for obfuscating the contents of communications. Any piece of written communication has some set of symbols that constitute allowed constructs, typically, words, syllables, or other meaningful ideas. Some of the simple methods first used involved simply manipulating this symbol set, which the cryptologic community often calls an alphabet regardless of the origin of the language. Other older tricks involved jumbling up the ordering of the presentation of these symbols. Many of these techniques were in regular use up until a little more than a century ago; it is interesting to note that even though these techniques aren’t sophisticated,COPYRIGHTED newspapers often publish MATERIAL puzzles called cryptograms or cryptoquips employing these cryptographic techniques for readers to solve. Many books have been published that cover the use, history, and cryptanal- ysis of simple substitution and transposition ciphers, which we discuss in this chapter. (For example, some of the resources for this chapter are References [2] and [4].) This chapter is not meant to replace a rigorous study of these techniques, such as is contained in many of these books, but merely to expose the reader to the contrast between older methods of cryptanalysis and newer methods.
    [Show full text]
  • Caesar Cipher
    Caesar cipher In cryptography, a Caesar cipher, also known as Cae- (There are different definitions for the modulo operation. sar’s cipher, the shift cipher, Caesar’s code or Cae- In the above, the result is in the range 0...25. I.e., if x+n sar shift, is one of the simplest and most widely known or x-n are not in the range 0...25, we have to subtract or encryption techniques. It is a type of substitution cipher add 26.) in which each letter in the plaintext is replaced by a letter The replacement remains the same throughout the mes- some fixed number of positions down the alphabet. For sage, so the cipher is classed as a type of monoalphabetic example, with a left shift of 3, D would be replaced by A, substitution, as opposed to polyalphabetic substitution. E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence. The encryption step performed by a Caesar cipher is of- ten incorporated as part of more complex schemes, such 2 History and usage as the Vigenère cipher, and still has modern application in the ROT13 system. As with all single-alphabet sub- stitution ciphers, the Caesar cipher is easily broken and in modern practice offers essentially no communication security. 1 Example The transformation can be represented by aligning two alphabets; the cipher alphabet is the plain alphabet rotated left or right by some number of positions. For instance, here is a Caesar cipher using a left rotation of three places, equivalent to a right shift of 23 (the shift parameter is used as the key): Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ Ci- pher: DEFGHIJKLMNOPQRSTUVWXYZABC When encrypting, a person looks up each letter of the message in the “plain” line and writes down the corre- sponding letter in the “cipher” line.
    [Show full text]
  • Codebreaking Has Moved on Since Turing's Day, with Dangerous Implications 24 November 2014, by Bill Buchanan
    Codebreaking has moved on since Turing's day, with dangerous implications 24 November 2014, by Bill Buchanan something that changes the way it operates which is easy for Bob and Alice to convert, but difficult for Eve to find. In the first case, to read their messages Eve will have to crack the cipher – to work out what method it uses to change plain text to cipher text. For example, the famous Julius Caesar cipher is a form of substitution cipher that shifts letters in the alphabet a number of places, for example a shift of 13 means A becomes N, B becomes O, C becomes P and so on. This is an easy code to crack, as there are only 25 unique shifts. Far harder would be a scrambled alphabet, in After decades of cracking, the cracks are appearing in which any letter can be mapped to any other letter cryptography. Credit: infobunny, CC BY without the same substitution shift applying to all, as with the Caesar cypher. This leads to a colossal number of permutations – 403 million billion billion – that, even with a supercomputer with which to try a We have always been been intrigued by keeping billion mappings per second, would still take an secrets and uncovering the secrets of others, average 6.3 billion years to crack. whether that's childhood secret messages, or secrets and codebreaking of national importance. However, these ciphers' fundamental weakness is the occurrence of the letters: in English, the letter With a film, The Imitation Game, reprising the life with the most occurrences is likely to represent an of Alan Turing and his role in breaking the Nazi's E, the most common in the language.
    [Show full text]
  • Substitution Cipher in Cryptography, a Substitution Cipher Is a Method Of
    Substitution cipher In cryptography, a substitution cipher is a method of encryption by which units of plaintext are replaced with ciphertext according to a regular system; the "units" may be single letters (the most common), pairs of letters, triplets of letters, mixtures of the above, and so forth. The receiver deciphers the text by performing an inverse substitution. Substitution ciphers can be compared with transposition ciphers. In a transposition cipher, the units of the plaintext are rearranged in a different and usually quite complex order, but the units themselves are left unchanged. By contrast, in a substitution cipher, the units of the plaintext are retained in the same sequence in the ciphertext, but the units themselves are altered. There are a number of different types of substitution cipher. If the cipher operates on single letters, it is termed a simple substitution cipher; a cipher that operates on larger groups of letters is termed polygraphic. A monoalphabetic cipher uses fixed substitution over the entire message, whereas a polyalphabetic cipher uses a number of substitutions at different times in the message, where a unit from the plaintext is mapped to one of several possibilities in the ciphertext and vice-versa. Contents • 1 Simple substitution o 1.1 Examples o 1.2 Security for simple substitution ciphers • 2 Homophonic substitution • 3 Polyalphabetic substitution • 4 Polygraphic substitution • 5 Mechanical substitution ciphers • 6 The one-time pad • 7 Substitution in modern cryptography • 8 Substitution ciphers in popular culture Simple substitution 1 ROT13 is a Caesar cipher, a type of substitution cipher. In ROT13, the alphabet is rotated 13 steps.
    [Show full text]
  • Cryptography Lead 2012 ______
    CRYPTOGRAPHY LEAD 2012 _______________________________________________________________________________________________ Goals for the lesson: ● Learn the history of cryptography - from its purpose through early usage ● Learn the different keywords that deal with cryptography ● Learn several different ciphers, including historic and modern ● Encrypt and decrypt your own messages Important Links: ● “The Gold Bug” by Edgar Allen Poe - http://etext.virginia.edu/toc/modeng/public/PoeGold.html _______________________________________________________________________________________________ Activity #1: Cryptography Definitions What is purpose of encryption? Why use it? Do you use encryption? Examples: cell phone, gaming, banking, https Definitions: ● Cryptography - secret or hidden writing ● Cryptology - study of secrets ● Encryption/Decryption - the act of turning normal text ("plain text") into garbled mess ("ciphertext") ● Cipher - the algorithm for conversion Activity #2: History of Cryptography Early years (before modern era) ● Concerned solely with keeping messages secret ● Between governments, military leaders, spies, etc ● Very earliest cryptography - none… because not many people could read, including couriers ● First ciphers went into three main categories: transposition, substitution, and physical Transposition ciphers - kinda like word scrambles, but with a specific, regular way for scrambling ● Rail Fence ● Route ● Columnar Substitution ciphers - replacing a letter with another letter ● Caesar ● ROT13 ● Atbash (Hebrew) ● Pigpen (Masonic)
    [Show full text]