mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
daily-psk: simplify algorithm
This commit is contained in:
parent
1ee2491e66
commit
bd92237003
1 changed files with 13 additions and 21 deletions
34
daily-psk
34
daily-psk
|
@ -19,34 +19,26 @@
|
||||||
|
|
||||||
:local Months { "jan"; "feb"; "mar"; "apr"; "may"; "jun";
|
:local Months { "jan"; "feb"; "mar"; "apr"; "may"; "jun";
|
||||||
"jul"; "aug"; "sep"; "oct"; "nov"; "dec" };
|
"jul"; "aug"; "sep"; "oct"; "nov"; "dec" };
|
||||||
:local MonthTbl { 0; 3; 3; 6; 1; 4; 6; 2; 5; 0; 3; 5 };
|
|
||||||
|
|
||||||
:local MonthStr [ :pick $Date 0 3 ];
|
:local Month [ :pick $Date 0 3 ];
|
||||||
:local Month;
|
:local Day [ :tonum [ :pick $Date 4 6 ] ];
|
||||||
:local Day [ :pick $Date 4 6 ];
|
:local Year [ :pick $Date 7 11 ];
|
||||||
:local Century [ :pick $Date 7 9 ];
|
|
||||||
:local Year [ :pick $Date 9 11 ];
|
|
||||||
|
|
||||||
# get numeric value for month
|
|
||||||
:for MIndex from=0 to=[ :len $Months ] do={
|
:for MIndex from=0 to=[ :len $Months ] do={
|
||||||
:if ([ :pick $Months $MIndex ] = $MonthStr) do={
|
:if ($Months->$MIndex = $Month) do={
|
||||||
:set Month $MIndex;
|
:set Month ($MIndex + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# calculate day of week
|
:local A ((14 - $Month) / 12);
|
||||||
:local Sum 0;
|
:local B ($Year - $A);
|
||||||
:set Sum ($Sum + (2 * (3 - ($Century - (($Century / 4) * 4)))));
|
:local C ($Month + 12 * $A - 2);
|
||||||
:set Sum ($Sum + ($Year / 4));
|
:local WeekDay (7000 + $Day + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12));
|
||||||
:set Sum ($Sum + $Year + $Day);
|
:set WeekDay ($WeekDay - (($WeekDay / 7) * 7));
|
||||||
:set Sum ($Sum + $Month);
|
|
||||||
:set Sum ($Sum - (($Sum / 7) * 7));
|
|
||||||
|
|
||||||
:local Return ([ :pick [ :pick $DailyPskSecrets 0 ] ($Day - 1) ] . \
|
:return (($DailyPskSecrets->0->($Day - 1)) . \
|
||||||
[ :pick [ :pick $DailyPskSecrets 1 ] $Month ] . \
|
($DailyPskSecrets->1->($Month - 1)) . \
|
||||||
[ :pick [ :pick $DailyPskSecrets 2 ] $Sum ]);
|
($DailyPskSecrets->2->$WeekDay));
|
||||||
|
|
||||||
:return $Return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:local Date [ / system clock get date ];
|
:local Date [ / system clock get date ];
|
||||||
|
|
Loading…
Reference in a new issue