The Grand SCHEME of Things
I recently began reading “Structure and Interpretation of Computer Programs” as part of my “Learning Computer Science” project. I’m already enjoying it, and I’m going to be posting my notes and exercise solutions on this blog. Here’s some of the stuff I’ve read about until now.
Applicative vs. Normal Order of Evaluation
Applicative Order  Normal Order 

“evaluate the arguments and then apply”  “fully expand and then reduce” 
MIT Scheme follows the applicative order of evaluation.
Functions vs. Procedures
Functions  Procedures 

“what is”  “how to” 
e.g. “$y$ is the square root of $x$ if $y^2=x$.  e.g. Heron’s method of computing square roots: $y_{n+1}=\frac{y_n+\frac{y_n}{x}}{2};\,\,n\in\mathbb{N}$ where $y_0$ is the initial guess. The value approximation $y_n$ of the square root of $x$ improves with each recursive step. 
Recursion and Iteration
Recursion  Iteration 

Recursion is a process that can be described as a chain of deferred operations.  Iteration is a process that can be descibed completely, at any moment in time, by a fixed number of state variables. 
There is a difference between a recursive process and a recursive procedure. A recursive procedure refers to the syntax of calling a procedure within its own definition. A process is called recursive based on how it evolves when it is executed.
I was quite surprised to learn that an iterative process can be generated by a recursive procedure. For example, consider the following two procedures that computer the factorial of a given positive integer.
(define (factrecur n) (
(if (= n 1) 1
(* n (factrecur ( n 1))))))
(define (factiter n) (
(define (iter product count) (
(if (> count n) product
(iter (* count product) (+ count 1)))))
(iter 1 1))
Both factrecur
and iter
are recursive procedures. However, factiter
will generate an iterative process on execution. Look at the solution of Exercise 1.9 below for a better understanding.
The implementation of a programming language is said to be tailrecursive if an iterative process described by a recursive procedure is executed as an iterative process. Scheme is a tailrecursive implementation. For other languages, iterative processes must be explicitly expressed with keywords like for
, while
, or do
.
My solutions to the first 10 exercises from Chapter 1
Exercise 1.1
10 12 8 3 6 a b 19 #f 4 16 6 16
Exercise 1.2
(/ (+ 5 4 ( 2 ( 3 (+ 6 (/ 4 5))))) (* 2 ( 6 2) ( 2 7)))
Exercise 1.3
(define (bruh a b c)
(if (> a b) (if (> b c) (sos a b) (sos a c))
(if (> a c) (sos a b) (sos b c))))
(define (sos x y) (+ (* x x) (* y y)))
Exercise 1.4
The procedure calculates a + b
if b is positive and a  b
if b is negative. In other words, it calculates a + b
.
Exercise 1.5
With an interpreter that uses applicativeorder evaluation, the expression cannot be evaluated. This is because the interpreter will get stuck when it tries to evaluate (p)
. (p)
will evaluate to (p)
and the interpreter will keep trying to simplify it with no luck.
An interpreter that uses normalorder evaluation will never encounter (p)
and the program will return 0.
Exercise 1.6
The interpreter will get stuck in an infinite recursive loop and nothing will be returned.
This is because scheme uses applicativeorder evaluation. This means that the arguments of a procedure are evaluated before the procedure is applied. Since newif
is a procedure and not a special form, the interpreter calls sqrtiter
each time it tries to evaluate the elseclause of newif
. As a result, newif
is never applied and guess
is never returned even if it is goodenough?
Exercise 1.7
The guess is considered good enough if the improved guess is within 0.1% of the original guess.
(define (goodenough? guess x)
(< (abs ( guess (improve guess x))) (* 0.001 guess)))
Exercise 1.8
(define (cbrtiter oldguess guess x)
(if (cbrtgoodenough? oldguess guess) guess
(cbrtiter guess
(cbrtimprove guess x)
x)))
(define (cbrtimprove guess x)
(/ (+ (/ x (* guess guess)) (* 2 guess)) 3))
(define (cbrtgoodenough? oldguess guess)
(< (abs ( oldguess guess)) (* 0.001 oldguess)))
(define (cbrt x)
(cbrtiter 0 1.0 x))
Exercise 1.9
The first procedure generates a recursive process.
(+ 4 5)
(inc (+ 3 5))
(inc (inc (+ 2 5)))
(inc (inc (inc (+ 1 5))))
(inc (inc (inc (inc (+ 0 5)))))
(inc (inc (inc (inc 5))))
(inc (inc (inc 6)))
(inc (inc 7))
(inc 8)
9
The second procedure generates an iterative process.
(+ 4 5)
(+ 3 6)
(+ 2 7)
(+ 1 8)
(+ 0 9)
9
Exercise 1.10
(A 1 0)
= 1024
(A 2 4)
= 65536
(A 3 3)
= 65536
$f(n)=2n$
\[g(n)={\left\lbrace\begin{matrix}{0}&{\quad\text{if}\quad}{n}={0}\\ 2^n&{\quad\text{if}\quad}{n}\ge{1}\end{matrix}\right.}\] \[h(n)={\left\lbrace\begin{matrix}{0}&{\quad\text{if}\quad}{n}={0}\\ 2&{\quad\text{if}\quad}{n}={1} \\ 2^{h(n1)}&{\quad\text{if}\quad}{n}\ge{2}\end{matrix}\right.}\]My Scheme Setup
It’s irrelevant but, I’m using CHICKEN on WSL.
Until next time!
The Mechanics of Slender Structures
My notes from Chapter 3 of “An Introduction to the Mechanics of Solids” by Crandall and Dahl.

Summary of Chapter 2, “Introduction to Mechanics of Deformable Bodies” (according to 3.1)
Analysis of Deformable Bodies
 Study of forces and equilibrium requirements
 Study of deformation and conditions of geometric fit
 Application of forcedeformation relations

What is Chapter 3, “Forces and Moments Transmitted by Slender Members” all about?
We are going to be concerned with the study of forces and the equilibrium requirements, as applied to slender members.

What are Slender Members?
Those members of engineering structures whose lengths are much longer as compared to either of their crosssectional dimensions are called slender members. In case of loops, the diameter must be much larger than the thickness of the long rod that is looped.

What is the subscript notation we are using to denote forces and moments at a section in slender members?
We usually have two letters in the subscript.
For a force $F_{ab}$, $a$ denotes the direction of the vector perpendicular to the area of crosssection in consideration and, $b$ denotes the direction of the Force.
Thus, $F_{xx}$ is an axial force while $F_{xy}$ and $F_{xz}$ are shear forces.
Similarly, for a moment $M_{ab}$, $a$ has the same meaning as above and $b$ is the direction of the force that is responsible for this moment.
Hence, $M_{xx}$ is a twisting moment while $M_{xy}$ and $M_{xz}$ are bending moments.

What about the sign convention?
A positive force or moment on a positive face is positive. So is a negative force or moment on a negative face (implied by Newton’s third law). Here, positive and negative mean in a positive or negative coordinate direction respectively.

What problem solving approach do we usually follow, when we have multiple loads on a slender member?
The Method of Sections
 First, draw a free body diagram of the entire slender member and mark all the forces acting on it.
 Then, use the equations of equilibrium $\Sigma F = 0$ and $\Sigma M = 0$ to get relations between them.
 Finally, cut the member at a section of your choice and repeat step 2 on either of the resulting segments.

What is a shear force diagram?
A graph of shear force on a body versus the distance along a beam (from a given point) where it acts.

What is a bending moment diagram?
A graph of bending moment on a body versus the distance along a beam (from a given point) where it acts.

Why do we need these diagrams?
If we wanted to design a durable engineering structure, we would need to know the maximum forces that can act on the members of the structure. Further, knowing the force distribution may allow us to better arrange all the different members in the structure together. I’ve not personally designed any such structures but in my opinion, a well engineered structure is one which is easy to put together and take apart, kind of like Legos.

What is the Point of Contraflexure?
It is the point on a bending moment diagram where the bending moment changes its sign (i.e. positive to negative or vice versa). At this point the value of the bending moment is zero.

What is Intensity of Loading?
Intensity of loading, $q$ is defined as the limit,
\[q = \lim_{\Delta x\to0}\frac{\Delta F}{\Delta x}\]It’s dimensions are force per unit Length.
 How do we approach problems that have distributed loading conditions?

Calculating the Resultant Force
One method is to calculate the resultant force on the slender member.
\[\text{For forces acting in a single dimension,}\\ \text{Resultant Force, }R = \int qdx \\ \text{Centroid, }\bar{x} = \frac{\int qxdx}{R}\]where $q(x)$ is the intensity of loading  a function of $x$, the distance from an end of the member.
These can be obtained by writing the force and moment balance equations twice  once with $R$ and $\bar{x}$ and then with the RHS of the above equations  and comparing them.
The line of action of the resultant force passes through the centroid.
The formulae for forces acting in two and three dimensions are also similar.

Using Differential Equilibrium Relationships
Consider a very small element of the given slender member, analyse the shear forces and bending moments acting on it and then limit the small segment of length / area / volume to zero. This will give us differential equations that we can integrate to find relationships between forces. Use boundary conditions to find out the values of constants of integration.
Also,
\[\Sigma M_A = 0 \\\implies M_b + \Delta x\cdot(V+\Delta V) + (M_b + \Delta M_b) = 0 \\\implies V\Delta x + \Delta V\Delta x + \Delta M_b = 0 \\\implies V = \frac{\Delta M_b}{\Delta x}\Delta V\]In both the above equations, limiting $\Delta x\to0$ we get,
\[q(x)=\frac{dV}{dx}\\ V(x) = \frac{dM_b}{dx}\]

 What is the relationship between the shear force, bending moment and loading diagrams?
 The slope of the bending moment curve is the negative ordinate of the shear force curve.
 The slope of the shear force curve is the negative ordinate of the intensity of loading curve.

How do we approach problems that have distributed loading conditions but only in some segments, or with different magnitudes?
Use the method of sections along with either of the two methods above or, use Singularity Functions.

What are Singularity Functions?
Singularity functions are defined as,
\[f_n(x)=\langle x  a\rangle^n ={\left\lbrace\begin{matrix}{0}&{\quad\text{if}\quad}{x}\le{a}\\ (xa)^n&{\quad\text{if}\quad}{x}\gt{a}\end{matrix}\right.}\;\;(n\ge0)\]They have the following property,
\[\int_{\infty}^{x}\langle xa\rangle^n\;dx = \frac{\langle xa\rangle^{n+1}}{n+1}\;\;(n\ge0)\]There are two exceptions:
\[\int_{\infty}^{x}\langle xa\rangle_{1}dx=\langle xa\rangle^0\] \[\int_{\infty}^{x}\langle xa\rangle_{2}\;dx=\langle xa\rangle_{1}\]$\langle xa\rangle_{1}$ and $\langle xa\rangle_{2}$ are zero everywhere except at $x=a$ where they are infinite.
 What do singularity functions represent?

$\langle xa\rangle_{2}$
represents a unit concentrated moment.

$\langle xa\rangle_{1}$
represents a unit concentrated load. This is also known as the Dirac Delta function in physics.

$\langle xa\rangle^{0}$
represents a unit step.

$\langle xa\rangle^{1}$
represents a unit ramp.

$\langle xa\rangle^{2}$
represents a unit parabolic curve.


If there are no distributed loads present, where does the maximum bending moment occur?
It always occurs at a loading point.

Why?
When all forces lie in the same plane, the bending moment diagram consists only of straight line segments. And even when they don’t, the bending moment diagram consists only of concave outward curves.

🧬 Life and Meaning
“He who has a why to live can bear almost any how.” ~ Friedrich Nietzsche
I read this quote in Viktor Frankl’s Man’s Search for Meaning. I recall my friend saying something similar to me back when we were preparing for competitive exams.
For a long time since then, I’ve been trying to find meaning in my life. I’ve been questioning everything I do. Each time I reach the same answer. There is no why. It doesn’t matter what I do, because nothing matters.
These nihilistic thoughts were what used to occupy a major chunk of my time. I couldn’t focus on anything else, because I couldn’t  and still can’t  see how any of my actions matter in the grand scheme of things.
Yuval Noah Harari writes in Sapiens, “There are no gods in the universe, no nations, no money, no human rights, no laws and no justice outside the common imagination of human beings.”
And I believe Mr. Robot when he says, “We live in a kingdom of bullshit.”
The only reason I’m able to question everything I do is because life has been easy for me ever since I was born. I’m pretty sure I wouldn’t be asking all these questions if I had to spend 60 hours a week working minimum wage to support my family. This brings up another question  is all of this just an excuse? Is this just me trying to justify my inadequacy?
I don’t know.
Cal Newport writes in So Good They Can’t Ignore You, “If you want to love what you do, abandon the passion mindset (“what can the world offer me?”) and instead adopt the craftsman mindset (“what can I offer the world?”).”
I think he hits the nail right on the head. Life isn’t about taking, it’s about giving back. How will you contribute to your species? As the way I am right now, I don’t have much to offer the world, honestly speaking. I have to  and want to  keep learning and reading and improve my understanding of the world.
Shoko Makinohara says to Sakuta in Seishun Buta Yarou wa Bunny Girl Senpai no Yume wo Minai, “What I think, Sakutakun, is that life is here for us to become kinder. I live life every day hoping I was a slightly kinder person than I was the day before.”
My actions no longer feel inconsequential when my goal is to propel my species to greater heights. I become part of a larger movement. I feel I can bear almost any how, because I have a why. It doesn’t matter if everything is meaningless  I’m okay with taking part in the farce if that is what inches me closer to my goal. Besides, I’m very curious. I like learning about how things work, and how they can be made better. So I guess that, at least for now, that’s how I’m going to be spending my time.
“The mathematician does not study pure mathematics because it is useful; he studies it because he delights in it and he delights in it because it is beautiful.” ~ Henri Poincaré
CTE TechWeekend CTF 2020
I spent the past weekend solving challenges from CTE TechWeekend CTF, and I had a blast. The difficulty of the challenges was just above what I’m used to, but I managed to solve them all and bag first place 😀. Thanks to the organisers, Team BITSKrieg and CTE for organising this lovely event!
Since this is the first time I’m writing a CTF writeup, I decided to follow the tips given here.
Here’s my approach to some challenges that I had the most fun with:
1.
Challenge Name:  fives…fives…fives 

Challenge Description:  What Is Seen Is Temporary, But What Is Unseen Is Eternal. 
Challenge Category:  Reverse Engineering 
Challenge Points:  497 
TL; DR:  Use Ghidra to analyse the provided binary and rewrite logic in Python. 
The first thing I did was check the file type. Then, I imported it into Ghidra’s CodeBrowser and looked at the decompiled code for the main
function. The program basically performed some operations on a hardcoded array, and then checked the input against it. If we passed the flag to the program, it would congratulate us. At the time, I simply wrote the decompiled code in Python  which was about 27 lines  without thinking too much about it. However, when writing this post, I realised that the operation was actually pretty straightforward, and it also explained the challenge name and the flag:
arr = [0x195, 0x140, 0x15e, 0x181, 0x19a, 0x186, 0x177, 0x145, 0x276, 0xf0,
0x235, 0xf5, 0x26c, 0x1c2, 0x181, 0x109, 0x208, 0x10e, 0x1c2, 0x177,
0x1c2, 0xf0, 0x235, 0xf5, 0x26c, 0x1c2, 0x1d1, 0x109, 0x1b3, 0x1b3,
0x10e, 0x1e5, 600]
print(''.join([chr(int(i/5)^5) for i in arr]))
TECHWKND{5t4y_H0m3_N_5t4y_X0RR3d}
What I’d like to do next: Read about reverse engineering, learn assembly, improve my code reading comprehension.
2.
Challenge Name:  My Private Message 

Challenge Description:  I forget what the opposite of compile was. I’m sure it was somethingcompile. 
Challenge Category:  Cryptography 
Challenge Points:  448 
TL; DR:  Decompile the given .pyc file, convert the hardcoded array as: decimal > hex > ASCII. 
I felt that this challenge was similar to the above one. I decompiled the given “message.pyc” file by uploading it to pythondecompiler.com. The program encrypted the input string and compared it against a hardcoded array. It was just a matter of figuring out the encryption algorithm. The input string was being converted to hexadecimal which was then converted to decimal. The decryption algorithm was just the reverse of this.
encoded = [361939290199, 323435658101, 474110520688, 521506348907,
473259521375, 512849360735, 212055061040, 237085094704,
409954706557]
print(bytearray.fromhex(''.join([hex(i)[2:] for i in encoded])).decode())
TECHWKND{unc0mpyl3_kn0w5_wh47_1_wr073_s0_s4d}
It seems from the flag that they expected me to use a package called uncompyle to decompile the given file.
What I’d like to do next: Read about the implementation of uncompyle.
3.
Challenge Name:  The Bourne Identity 

Challenge Description:  Jesus Christ, it’s JSON Bourne 
Challenge Category:  Web 
Challenge Points:  257 
TL; DR:  Inject JSON to overwrite the “admin” value. 
From the provided index.js
file, here is all we need to solve the challenge:
var data= '{"admin":"no", "user":"'+request.body.uname+'", "pass":"'+request.body.psw+'"}';
var obj= JSON.parse(data)
var hash= crypto.MD5(obj.pass)
if (obj.user=="\x4a\x42\x6f\x75\x72\x6e\x65" && hash=="a883241dd51bda403ae5d9eb14e41331")
{
if(obj.admin=="yes")
{
response.send('<h2>ACCESS GRANTED</h2><br><p>'+process.env.FLAG+'</p>');
}
}
Converting the username from hex to ASCII and decrypting the MD5 hash, we get the following user credentials:
user: JBourne
pass: mattdamon
However, this isn’t enough. We also need to somehow set obj.admin="yes"
. If we provide the following credentials,
user: JBourne", "admin":"yes
pass: mattdamon
Here’s what the variable data
would look like:
data = '{"admin":"no", "user":"JBourne", "admin":"yes", "pass":"mattdamon"}';
This will get us the flag,
TECHWKND{b0uRN3_2_h4Ck_Gq9jh}
Note that we cannot inject JSON in place of the password, because it is being hashed and compared.
I liked these challenges because these couldn’t be solved with just a tool and required some thinking. I used many tools in this competition, and I would like to read more about their implementations next. All in all, I think this CTF was a great experience and I would definitely participate again.
🍩 Topological Spaces
Basic Definitions

What is a topology?
A topology on a set X is a collection $\tau$ of subsets of X such that
 $\phi$ and X are in $\tau$.
 The union of the elements of any subcollection of $\tau$ is in $\tau$.
 The intersection of the elements of any finite subcollection of $\tau$ is in $\tau$.

What is a topological space?
A topological space is an ordered pair (X, $\tau$) consisting of a set X and a topology $\tau$ on X.

What is an open set?
If X is a topological space with topology $\tau$, we say that a subset U of X is an open set of X if U belongs to the collection $\tau$, i.e.,
\[U\subseteq X\text{ is open if }U\in\tau\] 
What is a discrete topology?
If X is any set, the collection of all subsets of X (i.e. $\mathcal P(x)$) is a topology on X, it is called the discrete topology on X.

What is an indiscrete topology?
The collection consisting of X and $\phi$ only is a topology on X; it is called the indiscrete topology, or the trivial topology on X.

What are comparable topologies?
Suppose that $\tau$ and $\tau’$ are two topologies on a given set X. If $\tau\subseteq\tau’$ we say that $\tau’$ is finer than $\tau$ or $\tau$ is coarser than $\tau’$. If $\tau\subset\tau’$ we say that $\tau’$ is strictly finer than $\tau$ or $\tau$ is strictly coarser than $\tau’$. We say that $\tau$ is comparable to $\tau’$ if either is contained in the other.
Munkres writes that, “This terminology is suggested by thinking of a topological space as being something like a truckload full of gravel—the pebbles and all unions of collections of pebbles being the open sets. If now we smash the pebbles into smaller ones, the collection of open sets has been enlarged, and the topology, like the gravel, is said to have been made finer by the operation.”
A Couple of Examples of Topologies

Finite Complement Topology (a.k.a. cofinite topology)
Let $X$ be a set, let $\tau_f$ be the collection of all subsets $U$ of $X$ such that $X\setminus U$ either is finite or is all of $X$. Then $\tau_f$ is a topology on $X$, called the finite complement topology.
 Proof
 $X\setminus X=\phi$ is finite. $X\setminus\phi=X$ is all of $X$. Thus, both $X\text{ and }\phi\in\tau_f$.

Consider an indexed subcollection ${T_\alpha}$ of $\tau_f$. Then for any $T_\alpha,\,X\setminus T_\alpha$ is finite. Hence,
\[X\setminus\bigcup_\alpha T_\alpha = \bigcap_\alpha X\setminus T_\alpha\]which is an intersection of finite sets and is thus finite. Therefore, $\bigcup_\alpha T_\alpha\in\tau_f$

Consider a finite indexed subcollection ${T_\alpha}$ of $\tau_f$. Then,
\[X\setminus\bigcap_\alpha T_\alpha = \bigcup_\alpha X\setminus T_\alpha\]which is a finite union of finite sets and is hence finite. Therefore, $\bigcap_\alpha T_\alpha \in\tau_f$.
 Proof

Countable Complement Topology
Let $X$ be a set, let $\tau_c$ be the collection of all subsets $U$ of $X$ such that $X\setminus U$ either is countable or is all of $X$. Then $\tau_c$ is a topology on $X$.
 Proof
 $X\setminus\phi = X$ is all of $X$. $X\setminus X=\phi$ is countable with zero elements. Thus, both $\phi\text{ and }X\in\tau_c$.

Let ${T_\alpha}$ be an indexed subcollection of $\tau_c$. Then, we can write,
\[X\setminus\bigcup_\alpha T_\alpha = \bigcap_\alpha X\setminus T_\alpha\]which is an intersection of countable sets ( $\forall\alpha, \,\,X\setminus T_\alpha\text{ is countable}$ ) and is hence countable.

Let ${T_\alpha}$ be a finite indexed subcollection of $\tau_c$. Then, we can write,
\[X\setminus\bigcap_\alpha T_\alpha = \bigcup_\alpha X\setminus T_\alpha\]which is a finite union of countable sets and is hence countable.
 Proof
Previous Page: 1 of 6 Next