Decompress and decrypt .png file - encryption

I have a multiple .png file, compressed (i guess) and encrypted with RC4, I fugired dencrypt them if has 02 flag but some of files have a 03 flag for this reason i can't sure what should I do with them.
I created small script for files keys come from older version of libRedAlert.so file attached link belong newer version of the file.
How can I dencrypt files with 03 header ?
goto 2
get tur byte
goto 3
get boyut byte
set boyutint byte boyut
print "%boyutint%"
if tur == 2
if boyut = 0
set KEY binary "BHnvp0MzjCkWQFqKmV8UcAkp7UIijyYu"
elif boyut = 1
set KEY binary "vpdLsd2Wb24ViPZytJrpqyTf9P6AOscV"
elif boyut = 2
set KEY binary "isoEmK7iFG1dbqrxqFTJzg1C9W1dIyqt"
elif boyut = 3
set KEY binary "exlirtfDws3ARqhSuGwBjpgUf4fZlFng"
elif boyut = 4
set KEY binary "wpbOslaZ7yoSIhTAqL5GQvzpreafUyIB"
elif boyut = 5
set KEY binary "NC247A9468oIbN06Dl33bAWNRT564G6h"
elif boyut = 6
set KEY binary "KEMM57pmw5tlNwd8mXVWzknFtoPZC1kW"
elif boyut = 7
set KEY binary "82UWUczlZ7lRF7UHp5IIhk6vWDDtF9TN"
elif boyut = 8
set KEY binary "Y2GjxmxZf6tybbnsToL2yDXIM78gPFIz"
elif boyut = 9
set KEY binary "YhynPDvwXGOCRdcfh0MqOA45L4NxOK9H"
elif boyut = 10
set KEY binary "ePLkqVjpC2J5xMNWMg5UeQRmuVuqd2fK"
elif boyut = 11
set KEY binary "dwkwTHXGV3gUP8ruVz82lE9bl4hOzMca"
elif boyut = 12
set KEY binary "Vm803WsmeAzoKSehjwk58vC9BKzpCa97"
elif boyut = 13
set KEY binary "onlqzhRdk5DXEUxDNl2ycOxgOiqYRV7N"
elif boyut = 14
set KEY binary "jD53QsARsnfToMEFGtRQf2DttA9VlfjM"
elif boyut = 15
set KEY binary "2tjc6ZYSzPcDL4BmqyajRYiGRMc3LQDM"
elif boyut = 16
set KEY binary "O40LK56qOAN77cgSntQpqj2Jed7CFjkw"
elif boyut = 17
set KEY binary "89v8YQPXlgwtmpN5SPoaqqaV7F3A4O60"
elif boyut = 18
set KEY binary "w5fdDE8ckG1U2WfrCx90OoGv5NecaQhV"
elif boyut = 19
set KEY binary "r6BRiUCtaYkTOCn29NPAUlwGyOQLvrli"
elif boyut = 20
set KEY binary "wO4oHSn71Xkz8uOSM5i8e3YFTw9D9sHw"
elif boyut = 21
set KEY binary "Y1FweX2iDHsn7UsuzKAQNBi5TrLBjgBu"
elif boyut = 22
set KEY binary "lHxpT130gjF0KH1JJvgDABNBnkhj6yu1"
elif boyut = 23
set KEY binary "ohXYm9jjX5HyfHZRamO9ijQO3Pa7ysoD"
elif boyut = 24
set KEY binary "mcozkxPR9NrTPsHPjPwVioskHvJ60XMn"
elif boyut = 25
set KEY binary "oAWP9EYBjjKoyfITbftSSxSduXzpyrt8"
elif boyut = 26
set KEY binary "cp0EEIES1nnMukpnIsQ3GByDKn7FRCUY"
elif boyut = 27
set KEY binary "6D8HhjTzdJ9ndmVNlHoByUkBF9vTfAGU"
elif boyut = 28
set KEY binary "7LfUsmIGJttnldf8QJhYnLSgCVCsYefO"
elif boyut = 29
set KEY binary "wH0m8i550z5DCXxrog4npkldpKspIPVA"
elif boyut = 30
set KEY binary "rDsnIrlu9KUxV3PBPB0AJyl6YvK0rT9D"
elif boyut = 31
set KEY binary "UqVR7MFIbxn8MQRsnvzOVB6yjJJrrkZy"
else
print "Something wrong"
endif
print "%KEY%"
goto 4
get size long
savepos offset
encryption rc4 KEY
#math SIZE - OFFSET
get NAME basename
string NAME += ".png"
log NAME offset size
endif
keys.so file
example file -This one works with program
example file -This one not works with program

Related

The encryption won't decrypt

I was given an encrypted copy of the study guide here, but how do you decrypt and read it???
In a file called pa11.py write a method called decode(inputfile,outputfile). Decode should take two parameters - both of which are strings. The first should be the name of an encoded file (either helloworld.txt or superdupertopsecretstudyguide.txt or yet another file that I might use to test your code). The second should be the name of a file that you will use as an output file.
Your method should read in the contents of the inputfile and, using the scheme described in the hints.txt file above, decode the hidden message, writing to the outputfile as it goes (or all at once when it is done depending on what you decide to use).
The penny math lecture is here.
"""
Program: pennyMath.py
Author: CS 1510
Description: Calculates the penny math value of a string.
"""
# Get the input string
original = input("Enter a string to get its cost in penny math: ")
cost = 0
Go through each character in the input string
for char in original:
value = ord(char) #ord() gives us the encoded number!
if char>="a" and char<="z":
cost = cost+(value-96) #offset the value of ord by 96
elif char>="A" and char<="Z":
cost = cost+(value-64) #offset the value of ord by 64
print("The cost of",original,"is",cost)
Another hint: Don't forget about while loops...
Another hint: After letters -
skip ahead by their pennymath value positions + 2
After numbers - skip ahead by their number + 7 positions
After anything else - just skip ahead by 1 position
The issue I'm having in that I cant seem to get the coding right to decode the file it comes out looking the same. This is the current code I have been using. But once I try to decrypt the message it stays the same.
def pennycost(c):
if c >="a" and c <="z":
return ord(c)-96
elif c>="A" and c<="Z":
return ord(c)-64
def decryption(inputfile,outputfile):
with open(inputfile) as f:
fo = open(outputfile,"w")
count = 0
while True:
c = f.read(1)
if not c:
break;
if count > 0:
count = count -1;
continue
elif c.isalpha():
count = pennycost(c)
fo.write(c)
elif c.isdigit():
count = int(c)
fo.write(c)
else:
count = 6
fo.write(c)
fo.close()
inputfile = input("Please enter the input file name: ")
outputfile = input("Plese enter the output file name(EXISTING FILE WILL BE OVER WRITTEN!): ")
decryption(inputfile,outputfile)

Why gpg --encrypt fails with sub key packet with key flags 0x0C that never expires?

When I analyze the output of that gpg --list-packets output I see that the sub key packet never expires, and its key flags is 0C which is for "Encryption". (see output at the bottom.)
The public key packet is already expired but its key flags is 03 which stands for "Key Certification" | "Sign Data", and therefore is not needed for encryption.
Yet when I run gpg --always-trust -r user#user.com --encrypt abc I get this error:
gpg: user#user.com: skipped: unusable public key
gpg: abc: encryption failed: unusable public key
Why is this so? Why the "never expire" encryption key is not usable in this case? Is the fact that public key expired, regardless of what the key flags is, all sub keys automatically invalid?
Here is the output of gpg --list-packets user.public.key:
gpg: WARNING: using insecure memory!
gpg: please see http://www.gnupg.org/faq.html for more information
:public key packet:
version 4, algo 1, created 1471460125, expires 0
pkey[0]: [2048 bits]
pkey[1]: [17 bits]
:user ID packet: "userid <user#user.com>"
:signature packet: algo 1, keyid A5038DC251BC03DC
version 4, created 1471460130, md5len 0, sigclass 0x13
digest algo 2, begin of digest c4 fa
hashed subpkt 2 len 4 (sig created 2016-08-17)
hashed subpkt 9 len 4 (key expires after 2y0d0h0m)
hashed subpkt 27 len 1 (key flags: 03)
hashed subpkt 11 len 7 (pref-sym-algos: 2 3 4 7 8 9 10)
hashed subpkt 22 len 4 (pref-zip-algos: 2 1 0 3)
hashed subpkt 25 len 1 (primary user ID)
subpkt 16 len 8 (issuer key ID A5038DC251BC03DC)
data: [2046 bits]
:public sub key packet:
version 4, algo 1, created 1471460125, expires 0
pkey[0]: [2048 bits]
pkey[1]: [17 bits]
:signature packet: algo 1, keyid A5038DC251BC03DC
version 4, created 1471460131, md5len 0, sigclass 0x18
digest algo 2, begin of digest 7f 63
hashed subpkt 2 len 4 (sig created 2016-08-17)
hashed subpkt 27 len 1 (key flags: 0C)
subpkt 16 len 8 (issuer key ID A5038DC251BC03DC)
data: [2042 bits]
After further analysis this is what I came up to:
Instead of using gpg --list-packets I use gpg --with-colon, and I take the first pub key from the output. I have noticed that if the pub key is not expired then it always allows encryption. If pub is expired then it does not matter what sub is - the key is expired and gpg refuses to encrypt.
Example of the never expired public key with expired subkeys (using gpg --with-colon user.public.key)
pub:-:3072:1:BFDEF66008072C77:2016-08-21:::-:userid <user#user.com>:
sub:-:3072:1:1AF28CF198A6BEA3:2016-08-21:2018-08-21::: [expires: 2018-08-21]
sub:-:3072:1:DA2B5429D88156C7:2016-08-21:2016-08-26::: [expires: 2016-08-26]
This one will allow encryption.
See details how to process this output here:
https://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg.git;a=blob_plain;f=doc/DETAILS
Example of

Complex select in SQLite view

I have two tables where Security holds the access bit mask for a given NTFS file system scan and FileSystemRights which equates to the string representations for the well known bit masks. I need to create a view which exposes the expected (not just proper) string representations for a given bit mask. The problem is several enum values composite and contain combinations of lower values, so the desired idea is not to repeat the implicit values.
For example, a value of 1179817 (Security.Id = 24) should only report ReadAndExecute and Synchronize, excluding ExecuteFile, ListDirectory, Read, ReadAttributes, ReadData, ReadExtendedAttributes, ReadPermissions and Traverse, as those are all part of ReadAndExecute (eg. ReadAndExecute & Read == Read). Its obviously correct to show them all, but a user wants only to see the non implicit values.
I'm lost within the constraints of SQL to produce a join that behaves like this without some abysmal nested case that would be a nightmare to look at.
Does a better programmatic approach exist?
FileSystemRights
================
Id Name Value
-- ---- -----
1 None 0
2 ListDirectory 1
3 ReadData 1
4 WriteData 2
5 CreateFiles 2
6 CreateDirectories 4
7 AppendData 4
8 ReadExtendedAttributes 8
9 WriteExtendedAttributes 16
10 ExecuteFile 32
11 Traverse 32
12 DeleteSubdirectoriesAndFiles 64
13 ReadAttributes 128
14 WriteAttributes 256
15 Write 278
16 Delete 65536
17 ReadPermissions 131072
18 Read 131209
19 ReadAndExecute 131241
20 Modify 197055
21 ChangePermissions 262144
22 TakeOwnership 524288
23 Synchronize 1048576
24 FullControl 2032127
25 GenericAll 268435456
26 GenericExecute 536870912
27 GenericWrite 1073741824
28 GenericRead 2147483648
Security
========
Id FileSystemRights IdentityReference
-- ---------------- -----------------
20 2032127 BUILTIN\Administrators
21 2032127 BUILTIN\Administrators
22 2032127 NT AUTHORITY\SYSTEM
23 268435456 CREATOR OWNER
24 1179817 BUILTIN\Users
25 4 BUILTIN\Users
26 2 BUILTIN\Users
MyView
======
SELECT s.Id AS SecurityId,
f.Name
FROM Security s
JOIN FileSystemRights f
ON CASE f.Value
WHEN 0 THEN s.FileSystemRights = f.Value
ELSE (s.FileSystemRights & f.Value) == f.Value
END
ORDER BY s.Id, f.Name;
Add the actual value of the name to the query.
Then wrap another query around that to filter out values for the same entry that are a subset of another value:
WITH AllValues(SecurityId, Name, Value) AS (
SELECT s.Id,
f.Name,
f.Value
FROM Security s
JOIN FileSystemRights f
ON CASE f.Value
WHEN 0 THEN s.FileSystemRights = f.Value
ELSE (s.FileSystemRights & f.Value) == f.Value
END
)
SELECT SecurityId,
Name
FROM AllValues
WHERE NOT EXISTS (SELECT *
FROM AllValues AS AV2
WHERE AV2.SecurityId = AllValues.SecurityId
AND (AV2.Value & AllValues.Value) != 0
AND AV2.Value > AllValues.Value
)
ORDER BY 1, 2;

decoding an ASCII character message

I have no idea what im doing I need to decode mmZ\dxZmx]Zpgy, I have an example but not sure what to do please help!
If (EncryptedChar - Key < 32) then
DecryptedChar = ((EncryptedChar - Key) + 127) - 32
Else
DecryptedChar = (EncryptedChar - Key)
the key us unknown 1-100
Use ord and chr to convert between the ordinals (ord) of the ASCII value and the and the characters (chr) they represent.
Then you can loop through your string and apply the your algorithm to each.
For example:
import sys
SecretMessage = "mmZ\dxZmx]Zpgy"
Key = 88
for Letter in SecretMessage:
EncryptedChar = ord(Letter)
if (EncryptedChar - Key) < 32:
DecryptedChar = ((EncryptedChar - Key) + 127) - 32
else:
DecryptedChar = (EncryptedChar - Key)
sys.stdout.write(chr(DecryptedChar))
Run this to see the output. I'll leave the exercise of finding the key value 88 up to you (hint: it involves iterations). You also appear to be missing the first letter from SecretMessage (probably a :).

Number pattern for checkboxes in asp.net?

I have a database table which contanis a field name Province bits and it adds up the count of the pattern like:
AB-1
BC-2
CD-4
DE-8
EF-16.... and so on.
Now in the table entry I have a value-13(Province bit), which implies checkboxes against entry AB,CD,DE(adds up to 13)should be checked.
I am not able to get the logic behind the same, how can check only those checkboxes whose sum adds up to the entry in the table?
You need to check to see if the value is in the bitwise total.
if( interestedInValue & totalValue == interestedInValue)
{
// this value is in the total, check the box
}
Documentation on & http://msdn.microsoft.com/en-us/library/sbf85k1c(v=vs.71).aspx
e.g. 13 = 1 + 4 + 8
13 & 1 == 1 // true
13 & 2 == 2 // false
13 & 4 == 4 // true
13 & 8 == 8 // true
13 & 16 == 16 // false
EDIT: for more clarification
ab.Checked = 1 && ProvinceBit == 1 // checkbox AB
bc.Checked = 2 && ProvinceBit == 2 // checkbox BC
...
The field is using bit flags.
13 is 1101 binary.
So convert the value to bits and assign one bit to each checkbox.
By converting your number to a string, you can convert to an array or just iterate through the string. A bit brute force, but will give you what you need.
var value = 13
string binary = Convert.ToString(value, 2);
//binary = "1101"

Resources