Skip to content

Instantly share code, notes, and snippets.

View etodanik's full-sized avatar
:octocat:
Fixing an open source bug :)

Danny Povolotski etodanik

:octocat:
Fixing an open source bug :)
View GitHub Profile
@etodanik
etodanik / hebrew.php
Created October 3, 2012 19:13
Hebrew language helper functions
<?php
// Checks if the input text is Hebrew
function checkHebrew($str){
preg_match('/[א-ת]/u', $str, $match);
return ( mb_detect_encoding($str, 'UTF-8', true) == 'UTF-8' && !empty($match[0]) );
}
// Gets wrongly encoded text and outputs readable UTF-8 Hebrew
function ensureHebrew($str, $encodings = array('UTF16-LE', 'WINDOWS-1255')){
if(!checkHebrew($str)){
@etodanik
etodanik / isracard.js
Last active May 11, 2020 13:52
Checks the validity of a given Isracard credit card number
function isracardCheck(num) {
if(num.length < 8 || num.length > 9) return false;
var diff = "987654321",
sum = 0,
a = 0,
b = 0,
c = 0;
if(num.length < 9) num = "0" + num;
for(var i=1;i<9;i++){
sum += parseInt(diff.substr(i,1))*parseInt(num.substr(i,1));
<?php
function north_cast_api_data($content) {
if (is_numeric($content)) $content = intval($content);
else {
$unserialized_content = @unserialize($content);
// we got serialized content
if ($unserialized_content !== false) {
// make sure that integers are represented as such, instead of str
foreach ($unserialized_content as $fn => &$c) {
@etodanik
etodanik / loadKey.cpp
Created April 28, 2017 18:14
loadKey() function for Shabak Challenge Part 2
std::vector<EncryptionStepDescriptor> loadKey(string path) {
int count = 0;
ifstream file;
// We're storing our loaded descriptors in a vector
std::vector<EncryptionStepDescriptor> descriptors;
file.open(path, ios::binary);
cout << "Reading Key..." << endl;
if (file.is_open()) {
while (file.good()) {
// This is our descriptor structure that is going to hold the data loaded directly from the binary
@etodanik
etodanik / loadCipher.cpp
Created April 28, 2017 18:23
loadCipher() function for Shabak Challenge Part 2
std::vector<uint8_t> loadCipher(string path) {
int count = 0;
ifstream file;
std::vector<uint8_t> v;
file.open(path, ios::binary);
cout << "Reading Cipher..." << endl;
if (file.is_open()) {
while (file.good()) {
char c;
if (!file.read(&c, sizeof(c))) {
@etodanik
etodanik / getDecryptedChar.cpp
Created April 28, 2017 18:30
getDecryptedChar() function for Shabak Challenge Part 2
uint8_t getDecryptedChar(uint8_t c, uint8_t operationCode, uint8_t operationParameter) {
switch (operationCode) {
case Xor:
return c ^ operationParameter;
break;
case Add:
return c + operationParameter;
break;
case Subtract:
return c - operationParameter;
@etodanik
etodanik / getOperationName.cpp
Created April 28, 2017 18:31
getOperationName() function for Shabak Challenge Part 2
string getOperationName(uint8_t code) {
switch (code) {
case Xor:
return "Xor";
break;
case Add:
return "Add";
break;
case Subtract:
return "Subtract";
@etodanik
etodanik / main.cpp
Created April 28, 2017 18:38
main() function for the Shabak Challenge Part 2
int main()
{
// Load Key.bin into a vector of EncryptionStepDescriptor structures
std::vector<EncryptionStepDescriptor> descriptors = loadKey("C:\\Users\\Danny\\Documents\\Visual Studio 2015\\Projects\\LikeABoss\\Debug\\Key.bin");
// Load the encrypted message
std::vector<uint8_t> v = loadCipher("C:\\Users\\Danny\\Documents\\Visual Studio 2015\\Projects\\LikeABoss\\Debug\\EncryptedMessage.bin");
string str(v.begin(), v.end());
// The cursor keeps track of our current position in the encrypted message
@etodanik
etodanik / variant.cpp
Last active July 30, 2024 10:20
Get the current value of an std::variant at runtime in C++
// the "secret sauce" here is that everything has to happen at compile-time
// step 3) this gets called for every possible index at compile time
template <std::size_t index, class... Args> void visitor_impl(const std::variant<Args...>& variant)
{
// this code path narrows us down to the type that's currently in the variant
if (variant.index() == index)
{
// we now have the current value in a fully generic way
auto value = std::get<index>(variant);