Here are what I want do (1) convert date time to 6digit number ;(2)convert the 6digit number to the input date time. Any suggestion to do this?
Asked
Active
Viewed 343 times
-2
-
Can you write some example? What language you want to use? – kristyna Aug 02 '15 at 14:44
-
C or c++. I may add passphrase for the conversion. – user3097695 Aug 02 '15 at 14:47
-
For example, I have date time 08/01 2015 07:48. I want to convert it to a unique 6 digit. Someone can convert back to the same date time. – user3097695 Aug 02 '15 at 14:50
-
2That's too much information to be contained in a 6 digit number. There are going to be collisions. – Banex Aug 02 '15 at 15:20
-
If this does not work, I have to calculate the Crc value of year, month, and days, then hash the results into 2 digits. The hours and mins are converted into a unique 4 digits. – user3097695 Aug 02 '15 at 15:26
-
There are 86400 seconds in just one day. That's five digits. You already used up five of your six digits just for the time portion. It would be logically impossible to use a single digit to express a date range, in your situation that's longer than eleven days. Simple math proves what you're trying to do is logically impossible. – Sam Varshavchik Aug 02 '15 at 15:41
-
There is a way !! :) – mlwn Aug 02 '15 at 15:49
-
I have a ready solution written in python. do you care about it ? or should i convert it to C for you >?? – mlwn Aug 02 '15 at 15:56
-
What is the limit on the dates? 1 Jan 1AD to the present? 1 Jan 2000 to 31 Dec 2044? The length of the range will determine whether this is possible. – Beta Aug 03 '15 at 02:50
-
From current time to 2100 – user3097695 Aug 03 '15 at 04:47
1 Answers
0
The below is a python script that uses gtk (on linux) that I prepared for exactly the same purpose. If you are interested, I can convert it to C, or you can try to do so...
In order to try it, input the date as YYMMDDHHmmss
then click the convert button, ... very handy !!
The only thing, I had to use numbers and letters !!!!!
#!/usr/bin/python
import os
import sys
import pygtk
pygtk.require ( '2.0' )
import gtk
def to_digit(a):
if (a < 10) and (a >= 0):
return chr(48 + a)
elif (a < 36) and (a > 9):
return chr(55 + a)
elif (a < 60) and (a > 35):
return chr(61 + a)
else:
return chr(95)
#
def to_int(c):
if (ord(c) < 58) and (ord(c) > 47):
return ord(c)-48
elif (ord(c) < 91) and (ord(c) > 64):
return ord(c)-55
elif (ord(c) < 123) and (ord(c) > 96):
return ord(c)-61
#
def m_call(a):
st = ''
if a == 0:
return '0'
while a:
b = a % 100
a = a / 100
st = to_digit(b) + st
return st
#
def rev_m_call(st):
cumul = 0
for i in range(len(st)):
cumul += to_int(st[i:i+1])*pow(10,2*(len(st)-i-1))
return cumul
#
class frmMain:
def run_cmd(self, widget, data=None):
if data == 'o1':
self.output_entry.set_text (m_call(int(self.input_entry.get_text())))
elif data == 'o2':
self.input_entry.set_text (str(rev_m_call(self.output_entry.get_text())))
elif data == 'c':
self.input_entry.set_text ("")
self.output_entry.set_text ("")
else:
pass
def delete_event(self, widget, event, data=None):
print ("delete event occurred")
return False
def destroy(self, widget, data=None):
gtk.main_quit ()
def __init__(self):
self.WIDTH = 300
self.HEIGHT = 60
self.window = gtk.Window ( gtk.WINDOW_TOPLEVEL )
self.window.set_title ( "Give the date to convert to code!!" )
self.window.set_size_request ( self.WIDTH, self.HEIGHT )
self.window.set_resizable ( False )
self.window.connect ( "delete_event", self.delete_event )
self.window.connect ( "destroy", self.destroy )
self.window.set_border_width ( 2 )
vb = gtk.VBox ( False, 0 )
self.window.add ( vb )
hb = gtk.HBox ( True, 0 )
self.input_entry = gtk.Entry ()
hb.pack_start ( self.input_entry, False, True, 2 )
self.output_entry = gtk.Entry ()
hb.pack_start (self.output_entry, False, True, 2 )
vb.pack_start ( hb, False, True, 2 )
hb = gtk.HBox ( False, 0 )
r1 = gtk.Button ( ">======->>" )
r1.connect ( "clicked", self.run_cmd, 'o1' )
hb.pack_end ( r1, False, False, 2 )
r2 = gtk.Button ( "<<-======<" )
r2.connect ( "clicked", self.run_cmd, 'o2' )
hb.pack_end ( r2, False, False, 2 )
clear_button = gtk.Button ( "Clear" )
clear_button.connect ( "clicked", self.run_cmd, 'c' )
hb.pack_end ( clear_button, False, False, 2 )
cancel_button = gtk.Button ( "Cancel" )
cancel_button.connect ( "clicked", self.destroy )
hb.pack_end ( cancel_button, False, False, 2 )
vb.pack_start ( hb, False, True, 2 )
self.window.show_all ()
def main(self):
gtk.main()
if __name__ == "__main__":
run = frmMain ()
run.main ()

mlwn
- 1,156
- 1
- 10
- 25
-
I will try to understand the code and do some testing on Monday. Thanks. – user3097695 Aug 03 '15 at 04:54
-
I have hard time to convert the code into C or C++. It would be nice to convert the functions to c. – user3097695 Aug 03 '15 at 15:03
-
-
This post is put on hold... I cannot answer it more here... I have pasted the answer in C language to pastebin .. cheers.. http://pastebin.com/3xADXpi3 – mlwn Aug 03 '15 at 21:01
-