def convert_radix(source_number_str, source_radix, destination_radix):
number = int(source_number_str, source_radix)
result = ''
while source_number > 0:
result += str(number % destination_radix)
number //= destination_radix
return result[::-1]
x = convert_radix('A13', 16, 10)
print(x) # 2579
function Invoke-MS16-032 {
<#
.SYNOPSIS
PowerShell implementation of MS16-032. The exploit targets all vulnerable
operating systems that support PowerShell v2+. Credit for the discovery of
the bug and the logic to exploit it go to James Forshaw (@tiraniddo).
Targets:
* Win7-Win10 & 2k8-2k12 <== 32/64 bit!
* Tested on x32 Win7, x64 Win8, x64 2k12R2
Notes:
* In order for the race condition to succeed the machine must have 2+ CPU
cores. If testing in a VM just make sure to add a core if needed mkay.
* The exploit is pretty reliable, however ~1/6 times it will say it succeeded
but not spawn a shell. Not sure what the issue is but just re-run and profit!
* Want to know more about MS16-032 ==>
https://googleprojectzero.blogspot.co.uk/2016/03/exploitinfE&6W74f&6W72РD6&W7VBW&V3%ӣ66TFRE&6W74fF&VBРРР2'V76Rb7FvF6bVFvR66PРE7F'EFV&6R7FРE6fTwV&B7FРЧ
Ivan \0Golubkov\0
Ivan Golubkovv\0
void append_str(char* first, char* second) {
char* end_of_first = first;
while(*end_of_first != '\0') {
end_of_first++;
}
char* current = second;
while(*current != '\0') {
*end_of_first = *current;
end_of_first++;
current++;
}
*end_of_first = '\0'; // Самое важное
}
Т.е. при помощи циклов и условных операторов, чтобы было понятно как это работает, чтобы не было скрытых действий таких, как myArray.Max. или myArray.Min.
using System;
using System.Collections.Generic;
using System.Linq;
var array = new[] {3, 10, 16, 2, 8};
var result = FindMediumPoint(array);
Console.WriteLine(string.Join(" ", result));
static IEnumerable<int> FindMediumPoint(int[] sequence)
{
var min = sequence.Min(); // Минимум
var max = sequence.Max(); // Максимум
var diff = max - min; // Разброс между минимумом и максимумом
var avg = diff / 2; // Середина "Разброса"
var center = min + avg;
var actualCenterDiffs = sequence
.Select(number => number - center) // Находим отклонение числа
.GroupBy(Math.Abs) // Группируем те числа, у которых одинаковое абсолютное отклонение
.OrderBy(x => x.Key) // Сортируем в порядке увеличения отклонения
.First(); // Берём первое по порядку (минимальное)
return actualCenterDiffs
.Select(diff => diff + center); // Применяем отклонение к найденному центру;
}
var dictionary = new Ditionary<string, string>();
string[] keys = dictionary.Keys.ToArray(); // ToArray - это метод-расширение (extension method)