Skip to content

Instantly share code, notes, and snippets.

View sheilambadi's full-sized avatar
🎯
Focusing

Sheila Mbadi sheilambadi

🎯
Focusing
  • Carnegie Mellon University Africa
  • Kigali, Rwanda
View GitHub Profile
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.HttpClientBuilder;
import org.json.JSONObject;
@sheilambadi
sheilambadi / rsa_algo.py
Created February 15, 2020 13:28
Calculate the decryption key and generate an encrypted message using the public key for RSA algorithm.
print('Compute d')
x = filter(lambda x: x*3 % 160 == 1, range(1,1000))
for i in x:
print(i)
print('\nEncryption')
enc_msg = pow(5,3) % 187
print(enc_msg)
@sheilambadi
sheilambadi / view_ssh_cert.sh
Created February 15, 2020 13:43
Obtain website certificate and view public key (by printing certificate in text form)
openssl s_client -connect www.cmu.edu:443 -tls1 -servername www.cmu.edu | openssl x509 -text
@sheilambadi
sheilambadi / bitplay.c
Created May 18, 2020 09:33
Exercise 2-7. Write a function invert(x,p,n) that returns x with the n bits that begin at position p inverted (i.e., 1 changed into 0 and vice versa), leaving the others unchanged.
#include <stdio.h>
unsigned int invert(unsigned int x, int p, int n);
int main()
{
unsigned int x;
unsigned int y;
unsigned int z;
@sheilambadi
sheilambadi / if_else_bash.sh
Last active January 29, 2021 16:14
If then else statement in bash
if [ logical expression ]; then
statement 1
statement 2
else
statement 3
statement 4
fi
@sheilambadi
sheilambadi / if_bash_alt.sh
Last active August 6, 2020 20:53
Alternative code for if then else statement in bash
if [ logical expression ]; then
statement 1
statement 2
fi
if [ logical expression ]
then
statement 1
statement 2
fi
@sheilambadi
sheilambadi / elif_bash.sh
Created August 6, 2020 21:03
Elif statement bash
if [ logical expression ]; then
statement 1
statement 2
elif [ logical expression ]; then
statement 3
statement 4
elif [ logical expression ]; then
statement 4
statement 5
fi
@sheilambadi
sheilambadi / logical_expressions.csv
Last active August 6, 2020 21:41
Logical expressions in bash
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 3.
Logical expression, Meaning
String comparion,
if [ -n "$variable" ], Returns true if the variable is empty/null
if [ -z "$variable" ], Returns true if the variable is not empty/null
if [ "$variable1" = "$variable2" ], Returns true if variable 1 is equal to variable 2
if [ "$variable1" == "$variable2" ], Returns true if variable 1 is equal to variable 2
if [ "$variable1" != "$variable2" ], Returns true if variable 1 is not equal to variable 2
if [ "$variable1" \< "$variable2" ], Returns true if variable 1 is less than variable 2 in ASCII. The < is escaped (\<)
if [ "$variable1" \> "$variable2" ], Returns true if variable 1 is greater than variable 2 in ASCII.
Integer comparison,
@sheilambadi
sheilambadi / conditional.sh
Last active August 6, 2020 21:52
Conditional integer comparison example
#!/bin/bash
variable=$1
if [ $variable -lt 0 ]; then
echo Variable is less than 0
elif [ $variable -eq 0 ]; then
echo Variable is equal to 0
elif [ $variable -gt 0 ]; then
echo Variable is greater than 0