Encrypted timestamp 448 bit - date

I try to reverse engineer an GWT-API of a local public transport company (MVG in Munich). They don't offer a public REST-API or something similar. Unfortunately they use some sort of encrypted timestamps which consists of 7 letters. The alphabet is A-Za-z0-9$_ (in this order) which makes 64 different letters. One would need 6 bits to represent these 64 different letters.
So 7 letters * 6 bits/letter makes 42 bits.
I'm pretty sure that it is no bit field.
You can see it yourself on http://www.mvg-live.de/MvgLive/MvgLive.jsp#haltestelle=Am%20M%C3%BCnchner%20Tor&gehweg=0&zeilen=7&ubahn=true&bus=true&tram=true. Look out for (POST) requests to clockservice (http://www.mvg-live.de/MvgLive/mvglive/rpc/clockService, not working without using POST) which gives you the current server time.
Here are a few examples, with the date of the http-response:
UeEcvQB: Tue, 29 Jul 2014 23:27:15 GMT
UeGbS0O: Wed, 30 Jul 2014 08:40:13 GMT
UeGbhiJ: Wed, 30 Jul 2014 08:41:13 GMT
UeGozGI: Wed, 30 Jul 2014 09:39:13 GMT
UeGpBv$: Wed, 30 Jul 2014 09:40:13 GMT
Any help is appreciated. Thanks.

Looks to be the number of milliseconds after the Unix epoch (01/01/1970 00:00:00) converted to base-64 using that alphabet.
E.g.: UeGozGI can be converted back to decimal using:
U = 20
e = 30
G = 6
o = 40
z = 51
G = 6
I = 8
To decimal:
= (((((20 * 64 + 30) * 64 + 6) * 64 + 40) * 64 + 51) * 64 + 6) * 64 + 8
= 1406713147784
= 07/30/2014 09:39:07am
Which is (pretty close to) the time you indicates it encodes.

Related

Filling a calendar using Arrayformula or LOOKUP

I've made a calendar sheet and would like to fill it using an Arrayformula or some kind of Lookup.
The problem is, the code in each cell is different, do I need it all to be the same code or is it possible to do an Arrayformula that does a different formula for each line?
I spent ages getting the calendar code working but would now like to simplify the code and I'm not sure what my next step should be:
https://docs.google.com/spreadsheets/d/1u_J7bmOFyDlYXhcL5dW3CHFJ1esySAKK_yPc6nFTdLA/edit?usp=sharing
Any advice would be much appreciated.
I've added a new sheet in your file called 'Aresvik'.
The green cells have new formula.
Cell B3 can be =date(B1,1,1)
Then each successive month can be =eomonth(B3,0)+1, =eomonth(J3,0)+1 etc.
The date formula in cell B5 is:
=arrayformula(iferror(vlookup(sequence(7,7,1),{array_constrain(sequence(40,1),day(eomonth(B3,0))+weekday(B3,3),1),query({flatten(split(rept(",",day(eomonth(B3,0))-1),",",0,0));sequence(day(eomonth(B3,0)),1,1)},"offset "&day(eomonth(B3,0))-weekday(B3,3)&" ",0)},2,false),))
It can be copied to each other cell below Mo, so B5 will change to J5, R5, Z5 etc.
Notes
The concept revolves around using the SEQUENCE function to generate a grid of numbers, 6 rows, 7 columns:
sequence(6,7)
which looks like this:
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35
36 37 38 39 40 41 42
Then using these numbers in a VLOOKUP to get a corresponding date for the calendar. If the first of the month falls on a Thursday (April 2021), the vlookup range needs 3 gaps at the top of the list of dates. player0 has a more elegant solution than my original query using offset, so I've incorporated it below. Cell Z3 is the date 1/4/2021:
=arrayformula(
iferror(
vlookup(sequence(6,7),
{sequence(day(eomonth(Z3,0))+weekday(Z3,2),1,0),
{iferror(sequence(weekday(Z3,2),1)/0,);sequence(day(eomonth(Z3,0)),1,Z3)}},
2,false)
,))
The first column in the vlookup range is:
sequence(day(eomonth(Z3,0))+weekday(Z3,2),1,0)
which is an array of numbers from 0, corresponding with the number of days in the month plus the number of gaps before the 1st day.
The second column in the vlookup range is:
{iferror(sequence(weekday(Z3,2),1)/0,);sequence(day(eomonth(Z3,0)),1,Z3)}},
It is an array of 2 columns in this format: {x;y}, where y sits below x because of the ;.
These are the gaps: iferror(sequence(weekday(Z3,2),1)/0,), followed by the date numbers: sequence(day(eomonth(Z3,0)),1,Z3)
(Example below is April 2021):
0
1
2
3
4
5
6 44317
7 44318
8 44319
9 44320
10 44321
11 44322
12 44323
13 44324
14 44325
15 44326
16 44327
17 44328
18 44329
19 44330
20 44331
21 44332
22 44333
23 44334
24 44335
25 44336
26 44337
27 44338
28 44339
29 44340
30 44341
31 44342
32 44343
33 44344
34 44345
35 44346
36 44347
The vlookup takes each number in the initial sequence (6x7 layout), and brings back the corresponding date from col2 in the range, based on a match in col1.
When the first day of the month is a Monday, iferror(sequence(weekday(BB1,2),1)/0,) generates a gap in col2 of the vlookup range. This is why col1 in the vlookup range has to start with 0.
I've updated the sheet at https://docs.google.com/spreadsheets/d/1u_J7bmOFyDlYXhcL5dW3CHFJ1esySAKK_yPc6nFTdLA/edit#gid=68642071
Values on the calendar are dates so the formatting has to be d.
If you want numbers, then use:
=arrayformula(
iferror(
vlookup(sequence(6,7),
{sequence(day(eomonth(Z3,0))+weekday(Z3,2),1,0),
{iferror(sequence(weekday(Z3,2),1)/0,);sequence(day(eomonth(Z3,0)),1)}},
2,false)
,))
shorter solution:
=INDEX(IFNA(VLOOKUP(SEQUENCE(6, 7), {SEQUENCE(DAY(EOMONTH(B3, ))+WEEKDAY(B3, 2), 1, ),
{IFERROR(ROW(INDIRECT("1:"&WEEKDAY(B3, 2)))/0); SEQUENCE(DAY(EOMONTH(B3, )), 1, B3)}}, 2, )))

How to convert alphabets to numerical values with spaces and return it back to alphabets?

Want to convert the alphabet to numerical values and transform it back to alphabets using some mathematical techniques like fast Fourier transform in MATLAB.
Example:
The following is the text saved in "text2figure.txt" file
Hi how r u am fine take care of your health
thank u very much
am 2.0
Reading it in MATLAB:
data=fopen('text2figure.txt','r')
d=fscanf(data,'%s')
temp = fileread( 'text2figure.txt' )
temp = regexprep( temp, ' {6}', ' NaN' )
c=cellstr(temp(:))'
Now I wish to convert cell array with spaces to numerical values/integers:
coding = 'abcdefghijklmnñopqrstuvwxyz .,;'
str = temp %// example text
[~, result] = ismember(str, coding)
y=result
result =
Columns 1 through 18
0 9 28 8 16 24 28 19 28 22 28 1 13 28 6 9 14 5
Columns 19 through 36
28 21 1 11 5 28 3 1 19 5 28 16 6 28 26 16 22 19
Columns 37 through 54
28 8 5 1 12 21 8 28 0 0 21 8 1 14 11 28 22 28
Columns 55 through 71
23 5 19 26 28 13 22 3 8 0 0 1 13 28 0 29 0
Now I wish to convert the numerical values back to alphabets:
Hi how r u am fine take care of your health
thank u very much
am 2.0
How to write a MATLAB code to return the numerical values in the variable result to alphabets?
Most of the code in the question doesn't have any useful effects. These three lines are the ones that lead to result:
str = fileread('test2figure.txt');
coding = 'abcdefghijklmnñopqrstuvwxyz .,;';
[~, result] = ismember(str, coding);
ismember returns, in the second output argument, the indices into coding for each element of str. Thus, result are indices that we can use to index into coding:
out = coding(result);
However, this does not work because some elements of str do not occur in coding, and for those elements ismember returns 0, which is not a valid index. We can replace the zeros with a new character:
coding = ['*',coding];
out = coding(result+1);
Basically, we're shifting each code by one, adding a new code for 1.
One of the characters we're missing here is the newline character. Thus the three lines have become one line. You can add a code for the newline character by adding it to the coding table:
str = fileread('test2figure.txt');
coding = ['abcdefghijklmnñopqrstuvwxyz .,;',char(10)]; % char(10) is the newline character
[~, result] = ismember(str, coding);
coding = ['*',coding];
out = coding(result+1);
All of this is easier to achieve just using the ASCII code table:
str = fileread('test2figure.txt');
result = double(str);
out = char(result);

Google App Script formatted date Match in Array without iterating

I am trying to find the first occurrence of a date, happens to be in 'MMM dd" format, within a coloumn, by using findIndex method.
The following code isnt able to achieve it
function copyInvoiceDetailsToDB() {
var sss = SpreadsheetApp.getActiveSpreadsheet();
var ss = sss.getSheetByName('Import MT Order Sheet'); //Source Sheet
var compareDate = ss.getRange(1,4).getValue(); // Search item
///var mmm = Utilities.formatDate(compareDate,"IST", 'MMM dd');
var reldata = ss.getRange('A3:AA'+ a).getValues();
var tss = SpreadsheetApp.openById("1xhPD6tlJiU33_tdnC82p-
e9rWA8mmMtI0g9jDLkk6s0"); // sheet being searched
var ss = tss.getSheetByName('DB');
var ssdata = ss.getRange('A:A').getValues(); // Range containing the values
var a = ssdata.indexOf(compareDate);
Logger.log(a);
Logger.log(compareDate);
Logger.log(ssdata);
return;
Generates the following log.
Please help me understand where I must be going wrong.
[17-11-22 02:40:11:568 IST] -1.0
[17-11-22 02:40:11:569 IST] Nov 22
[17-11-22 02:40:11:572 IST] [[], [Sun Nov 19 00:00:00 GMT+05:30 2017], [Mon Nov 20 00:00:00 GMT+05:30 2017], [Mon Nov 20 00:00:00 GMT+05:30 2017], [Mon Nov 20 00:00:00 GMT+05:30 2017], [Tue Nov 21 00:00:00 GMT+05:30 2017], [Tue Nov 21 00:00:00 GMT+05:30 2017], [Wed Nov 22 00:00:00 GMT+05:30 2017], [Wed Nov 22 00:00:00 GMT+05:30 2017], [Wed Nov 22 00:00:00 GMT+05:30 2017], [Wed Nov 22 00:00:00 GMT+05:30 2017], [Wed Nov 22 00:00:00 GMT+05:30 2017], [Wed Nov 22 00:00:00 GMT+05:30 2017], [Wed Nov 22 00:00:00 GMT+05:30 2017], [Wed Nov 22 00:00:00 GMT+05:30 2017], [Wed Nov 22 00:00:00
How about this answer? From your question, I understood as follows.
You want to retrieve the first occurrence (the row number?) of a date using a string 'MMM dd".
You want to understand for retrieving values using indexOf().
About retrieving values from array using indexOf()
When you want to retrieve a value from an array using indexOf(), the array has to be 1 dimensional array. This is pointed out by Sandy Good.
When a value is retrieved from an 1 dimensional array using indexOf(), it doesn't retrieve the value included in each element, it retrieves the same value for each element.
["foo", "bar", "baz"].indexOf("ba") is -1.
This means that there is no "ba" in each element in the array.
["foo", "bar", "baz"].indexOf("bar") is 1.
This means that there is "bar" at index 1 of the array.
When it retrieves the value included in each element, each element has to be used as a string.
["foo", "bar", "baz"].indexOf("ba") is -1.
"bar".indexOf("ba") is 0.
This means that the string of "ba" is found at 1st string in "bar". So in the case of "bbbar".indexOf("ba"), the result is 2.
The modification point reflected them is as follows.
Modification point :
From :
var a = ssdata.indexOf(compareDate);
Logger.log(a);
To :
var a;
for (var i in ssdata) {
if (ssdata[i][0].indexOf(compareDate) > -1) {
a = i;
break;
}
}
Logger.log(a);
a is the index with the value included "Nov 22" in the array of ssdata. If you want to the row number, please add 1 to it.
When your result shown at the log is used, a is 7.
References :
Array.prototype.indexOf()
String.prototype.indexOf()
If I misunderstand your question, I'm sorry.

How to solve calculations about logical address space and physical address space?

How to calculate number of bits in logical address and physical address when
logical address space of 8 pages of 1024 word each, mapped to physical memory of 32 frames?
15 is the correct answer
i think this is correct way
size of logical address space is No. of pages * Page size = 8 * 1024 = 2^3 * 2 ^10 = 2^13 No. of bits for logical address is 13
Size of Physical address space is 2^5 * 2^10 = 2^15 No. of bits for physical address is 15
Consider the following room/floor analogy: Each floor in a hotel contains 10 rooms. The door in each room is labeled 01, 02, 03, ..., 10. Then you get off the elevator, there is a plaque with the floor number. There are 3 floors in this hotel: floors 1, 2, and 3. Therefore, you can say that, to eliminate the ambiguity in room numbers, you concatenate the floor number to the room in the following format: floor:room. So, 1:01 is different than 2:01, or 3:01.
Viewing this graphically:
1 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 |
2 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 |
3 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 |
The floor number can be expressed with one digit. The room number can be expressed with two digits. To express the unique location of the room (floor:room concatenation), you need three digits. Replace floor with frame, and room with page.
There are 8 pages in logical address space so, 2^3 = 8 then page size of 3-bits
We have 1024 words(1 word = 2-bytes) then, 1024 * 2 = 2048 bytes
which we can say that 2^11 = 2048 then so there are 11 + 3 = 14-bits are the total number of bits in a logical address.
Now coming towards the Physical address:
we have 32 frames so 2^5 = 32 we have 5-bits for frame + 11 bits = 16-bits
then we have 16-bits for our physical address.
Offset for both pages and frames is the same to comply with design. In the problem, offset is 1024, so offset for page = offset for frame = 2^10.
Total bits needed to give logical address to each word of each page = 3+10.
Since there are 5 bits needed to uniquely define each frame,the Physical address will require 5+10 = 15 bits.
size of logical address space is No. of pages * Page size
= 8 * 1024
= 2^3 * 2 ^10 = 2^13
No. of bits for logical address is 13
Size of Physical address space is 2^5 * 2^10
= 2^15
No. of bits for physical address is 15
here i think the main memory information is not needed at all.
Given Total no of pages = 8 and page offset is 1024.
we know that logical address spaces is = total no of bits required to represent total no of pages + bits required to map page offset.
Hence total bits required = 3 (because total no of pages is 8 and to represent you need three bits) + 10 (page offset is 1024 so you need 10 bits) = 13 bits all total.
Thanks.
After searching the internet, i could find the solution for the question.
Each page/frame holds 1K; we will need 10 bits to uniquely
address each of those 1024 addresses. Physical memory has 32 frames and
we need 32 (2^5)
bits to address each frames, requiring in total 5+10=15 bits.
A logical address space of 8 pages requires 3 bits to address each page
uniquely, requiring 13 bits in total.
this tutorial will provide more details regarding this question

Find the longest run of sequential integers in a vector

I have a routine that returns a list of integers as a vector.
Those integers come from groups of sequential numbers; for example, it may look like this:
vector = 6 7 8 12 13 14 15 26 27 28 29 30 55 56
Note that above, there are four 'runs' of numbers (6-8, 12-15, 26-30 & 55-56). What I'd like to do is forward the longest 'run' of numbers to a new vector. In this case, that would be the 26-30 run, so I'd like to produce:
newVector = 26 27 28 29 30
This calculation has to be performed many, many times on various vectors, so the more efficiently I can do this the better! Any wisdom would be gratefully received.
You can try this:
v = [ 6 7 8 12 13 14 15 26 27 28 29 30 55 56];
x = [0 cumsum(diff(v)~=1)];
v(x==mode(x))
This results in
ans =
26 27 28 29 30
Here is a solution to get the ball rolling . . .
vector = [6 7 8 12 13 14 15 26 27 28 29 30 55 56]
d = [diff(vector) 0]
maxSequence = 0;
maxSequenceIdx = 0;
lastIdx = 1;
while lastIdx~=find(d~=1, 1, 'last')
idx = find(d~=1, 1);
if idx-lastIdx > maxSequence
maxSequence = idx-lastIdx;
maxSequenceIdx = lastIdx;
end
d(idx) = 1;
lastIdx=idx;
end
output = vector(1+maxSequenceIdx:maxSequenceIdx+maxSequence)
In this example, the diff command is used to find consecutive numbers. When numbers are consecutive, the difference is 1. A while loop is then used to find the longest group of ones, and the index of this consecutive group is stored. However, I'm confident that this could be optimised further.
Without loops using diff:
vector = [6 7 8 12 13 14 15 26 27 28 29 30 55 56];
seqGroups = [1 find([1 diff(vector)]~=1) numel(vector)+1]; % beginning of group
[~, groupIdx] = max( diff(seqGroups)); % bigger group index
output = vector( seqGroups(groupIdx):seqGroups(groupIdx+1)-1)
output vector is
ans =
26 27 28 29 30
Without loops - should be faster
temp = find ( ([(vector(2:end) - vector(1:end-1))==1 0])==0);
[len,ind]=max(temp(2:end)-temp(1:end-1));
vec_out = vector(temp(ind)+1:temp(ind)+len)