Confusing PermMask values in SharePoint Online - sharepoint

I came across the PermMask values while using JSLink in SharePoint Online for checking permissions of user from the ctx.CurrentItem.PermMask
The values for different permissions aren't matching with the Microsoft's documentation, any idea what these values represent? or they have to be converted into some other format? I haven't come across these values expect for the Admin permission whose value is 0x7fffffffffffffff
0x1b03c431aef - Edit
0xb008431041 - View Only
0x1b03c4312ef - Contribute
0x1b03c5f1bff - Design
0x7fffffffffffffff - Admin

webPermMasks are TWO 32-bit integers indicating which permissions a user has.
Each bit represents a permission.
(_spPageContextInfo.webPermMasks.High).toString(2)
(_spPageContextInfo.webPermMasks.Low).toString(2)
Displays the bits
High & Low
In the good old days computer worked with 8 bits, which someone named a Byte.
With 8 bits (8 permissions) you can only count from 0 to 255
So to store a larger number of 16 bits (0- 32768) on an 8-bit CPU you need 2 Bytes.
We called these the High-Byte and the Low-Byte
SharePoint has 37 types of permissions
Present computers have evolved from CPUs that can handle 8-bits to 16-bits to 32-bits
Currently SharePoint has 37 different Security permissions..
which do not fit in those 32 bits
Like so many moons ago you need TWO 32-bit values to encode Permissions
Which some Microsoft engineer with common sense named the High and Low value
The SP.js library (available standard on most pages) has the information on which Permission is which bit number
Run this in the developer console:
for (var permLevelName in SP.PermissionKind.prototype) {
if (SP.PermissionKind.hasOwnProperty(permLevelName)) {
var permLevel = SP.PermissionKind.parse(permLevelName);
console.info(permLevelName,permLevel);
}
}
}
Note permLevel is not the value, it is the bit-number
SP.PermissionKind.openItems is bit-number 6 and thus value 2^6
If you add up all the values you get the High order and Low order integer values for Permissions.
Note permLevel for SP.PermissionKind.manageAlerts is the 39th bit
This is in the High order integer, so the value is 2^(39-31)
webPermMasks
_spPageContextInfo.webPermMasks.Low
_spPageContextInfo.webPermMasks.High
Gives you 64 bits in TWO 32 bit Integers (with 37 permissions only a few are used in the High order)
indicating what Permissions the Current User has on the Current Page
All PermissionKinds (SP.PermissionsKnd.[name])
Note: This is the bit-number, not the value!
To check if someone has permissions,
You have to calculate the (summed) value then binary check against the High and Low order integers.
viewListItems: 1
addListItems: 2
editListItems: 3
deleteListItems: 4
approveItems: 5
openItems: 6
viewVersions: 7
deleteVersions: 8
cancelCheckout: 9
managePersonalViews: 10
manageLists: 12
viewFormPages: 13
anonymousSearchAccessList: 14
open: 17
viewPages: 18
addAndCustomizePages: 19
applyThemeAndBorder: 20
applyStyleSheets: 21
viewUsageData: 22
createSSCSite: 23
manageSubwebs: 24
createGroups: 25
managePermissions: 26
browseDirectories: 27
browseUserInfo: 28
addDelPrivateWebParts: 29
updatePersonalWebParts: 30
manageWeb: 31
anonymousSearchAccessWebLists: 32
useClientIntegration: 37
useRemoteAPIs: 38
manageAlerts: 39
createAlerts: 40
editMyUserInfo: 41
enumeratePermissions: 63
Use in script
The SP library supplies a function to check for individual levels:
SP.PageContextInfo.get_webPermMasks().has( [bitnumber] );
SP.PageContextInfo.get_webPermMasks().has( SP.PermissionKind.enumeratePermissions );
Using unused space (tales of the past)
Only a handfull of bits in the High Order integer are used by SharePoint.
Yet the database stores all 32 bits...
When we still built SharePoint Back End stuff we would use those unused bits for our own Permission scheme.
The free trials we let everyone install was actually the full blown product.
And when they bought the Licensed Product.. all it did was flip one bit in the database.
J1 iSPT

It's sum of Permissions.
For example:
View Only includes below permissions.
ViewListItems = 1
ViewVersions = 64
CreateAlerts = 549755813888
ViewFormPages = 4096
CreateSSCSite = 4194304
ViewPages = 131072
BrowseUserInfo = 134217728
UseRemoteAPIs = 137438953472
UseClientIntegration = 68719476736
Open = 65536
The sum is 756052856897=0xb008431041

Related

what is the need to divide a list sys.getsizeof() by 8 or 4 ( Depending upon the machine) after subtracting 64 or 36 from the list

I am trying to find the capacity of a list by a function. But a step involves subtracting the list size by 64 ( in my machine ) and also it has to be divided by 8 to get the capacity. What does this capacity value mean ?
I tried reading the docs of python to know about sys.getsizeof() method but still it couldn't answer my doubts.
import sys
def disp(l1):
print("Capacity",(sys.getsizeof(l1)-64)//8) // What does this line mean especially //8 part
print("Length",len(l1))
mariya_list=[]
mariya_list.append("Sugarisverysweetand it can be used for cooking sweets
and also used in beverages ")
mariya_list.append("Choco")
mariya_list.append("bike")
disp(mariya_list)
print(mariya_list)
mariya_list.append("lemon")
print(mariya_list)
disp(mariya_list)
mariya_list.insert(1,"leomon Tea")
print(mariya_list)
disp(mariya_list)
Output:
Capacity 4
Length 1
['Choco']
['Choco', 'lemon']
Capacity 4
Length 2
['Choco', 'leomon Tea', 'lemon']
Capacity 4
Length 3
This is the output. Here I am unable to understand what does capacity 4 mean. Why does it repeats the same value four even after subsequent addition of elements.

Constraining the range of decision variables based on other decision variables

I have a regular classroom assignment problem with course sizes and class capacities. Decision variables are binary. The model allows assigning one course to more than one room as long as the total capacity assigned is bigger than the course size. The constraint I want to add to this model is to make sure that the respective sizes of the rooms assigned to each course are within a reasonable range (say 20 seats) from each other. How can this be done in a linear way? How can I prevent the model from assigning a course of 60 students to 2 rooms of 10 and 50 capacities and instead make sure their sizes are close together (preferably even equal).
I'm using Excel with OpenSolver.
Here's some sample data:
Course/Room 324A 321D 124B 328 Course Size Capacity Assigned Wasted
Management 0 0 0 1 15 25 10
Engineering 1 0 0 0 20 20 0
Science 0 1 1 0 60 75 15
Room Sizes 20 40 35 25
The objective is to minimize the total space wasted (which is 25 seats in this example).
Introduce variables minseat and maxseat and form the inequalities:
minseat(course) <= seats(room)+(1-assign(course,room))*M
maxseat(course) >= seats(room)-(1-assign(course,room))*M
maxseat(course)-minseat(course) <= 20
Alternatively put maxseat(course)-minseat(course) in the objective with some cost factor. Choose M judiciously.

Bluetooth heartrate monitor byte decoding

Problem :
I am having trouble with understanding the returned data of the BLE Heart Rate Characteristic(service 180d, characteristic 2a37).
According to the specification there will be either 6 or 7 bytes of data (when base64-decoded), i fully understand how to deal with it when this is the case.
But sometimes it won't return 6 or 7 bytes but 8 and more rarely 4 bytes, i have no idea why there are more/less bytes and what the meaning of the added bytes is or which bytes are left out.
I could skip all the cases where there are not 6 or 7 bytes but i want to fully understand this.
I am certain that the converting the base64-encoded to byte-array is done correctly, i made a function for it and checked it using manual base64-decode combined with charCodeAt(index) and truly manually checked it using good ol' pencil, paper and brain (not necessarily in that order).
TL;DR :
BLE Heart Rate (180d,2a37) sometimes does not return the expected amount of bytes (4 and 8 when it should be either 6 or 7 bytes).
What exactly happened and why?
Example :
// Example results in byte-array's
["00010110", "01110111", "00000100", "00000010"] // unexpected 4 byte
["00010110", "01111000", "11111111", "00000001", "11111111", "00000001", "00001100", "00000001"] // unexpected 8 byte
["00010110", "01110111", "00001000", "00000010", "00001000", "00000010"] // normal 6 byte
// Example results in hex-array's (easier to read on small screens)
["0x16","0x77","0x04","0x02"] // unexpected 4 byte
["0x16","0x78","0xFF","0x01","0xFF","0x01","0x0C","0x01"] // unexpected 8 byte
["0x16","0x77","0x08","0x02","0x08","0x02"] // normal 6 byte
Byte Explanation :
Flags. The first bit (most right) is on if the heart rate is in 16 bit format (i only got 8 bit).
heartrate, if the heart rate is in 16 bit format there will be 2 bytes here
energy expended
energy expended
rr interval
rr interval
Energy expenditure is optional check the bit 3 of the flags in your sample data case it is not present. There are a variable number of rr intervals. with 4 bytes you have just 1 with 6 bytes you have 2 and with 8 bytes you have 3 you could in theory get 10 and 4.
You should decode the bytes using the flags then if rr's are present the number of bytes left / 2 is the number of rr's you have.
See the XML-Definition file for more details.

Hill cipher implementation when results are not expected

I am working on some ciphers (just theory, no coding yet). Currently I am doing the hill cipher and I can use it fine. However I have came across a problem which has stumped me. Say for example I am encrypting the letters A and I. A would be 0 and I 8. Now take my encryption box to be:
K= 18 2
23 0
This is all well and good. I can encrypt as such:
A = 18*0 = 0
2 *8 = 16
The problem is that adding these results produces 16. Is 16 % 26 just 16? Is this the number that I use for my encryption? Similar problem occurs if I have an encryption where the result is 260 % 26. Do this become 10 or 0? When you divide 260 by 26 you get 10. To finish the modulo operation I would take away any whole number and multiply the remainder by 26. Of course if I do it in this case then I get 0, which cannot be multiplied. Any suggestions?
Yes. 16 % 26 = 16 and 260 % 26 = 0.
The point is that your encryption matrix cannot be used as Hill cipher's encryption/decryption key.
The reason is that the encryption matrix must have an inverse matrix (modulo 26). In other words, the determinant of the matrix must be nonzero, and not divided by 2 or 13. In fact,
the determinant of your matrix is 24 mod 26, which cannot satisfy this requirement of the Hill cipher. This is why you got the strange result and the decryption will failed.
So try to generate another encryption matrix which has the required property. For example,
3 5
1 2 can be used as an encryption matrix.

A problem with connected points and determining geometry figures based on points' location analysis

In school we have a really hard problem, and still no one from the students has solved it yet. Take a look at the picture below:
http://d.imagehost.org/0422/mreza.gif
That's a kind of a network of connected points, which doesn't end and each point has its own number representing it. Let say the numbers are like this: 1-23-456-78910-etc. etc.. (You can't see the number 5 or 8,9... on the picture but they are there and their position is obvious, the point in middle of 4 and 6 is 5 and so on).
1 is connected to 2 and 3, 2 is connected to 1,3,5 and 4 etc.
The numbers 1-2-3 indicate they represent a triangle on the picture, but the numbers 1-4-6 do not because 4 is not directly connected with 6.
Let's look at 2-3-4-5, that's a parallelogram (you know why), but 4-6-7-9 is NOT a parallelogram because the in this problem there's a rule which says all the sides must be equal for all the figures - triangles and parallelograms.
Also there are hexagons, for ex. 4-5-7-9-13-12 is a hexagon - all sides must be equal here too.
12345 - that doesn't represent anything, so we ignore it.
I think i explained the problem well. The actual problem which is given to us by using an input of numbers like above to determine if that's a triangle/parallelogram/hexagon(according to the described rules).
For ex:
1 2 3 - triangle
11 13 24 26 -parallelogram
1 2 3 4 5 - nothing
11 23 13 25 - nothing
3 2 5 - triangle
I was reading computational geometry in order to solve this, but i gave up quickly, nothing seems to help here. One friend told me this site so i decided to give it a try.
If you have any ideas about how to solve this, please reply, you can use pseudo code or c++ whatever. Thank you very much.
Let's order the points 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
You can store this in a matrix. Now let row[i] = the row number i is on and col[i] = the column number i is on. These can be computed more or less efficiently for each i.
First, sort your given numbers ascendingly. You will need exactly 3 points for a triangle, 4 for a parallelogram and 6 for a hexagon - anything else and you can dismiss it as no-figure.
Notice that we can only have right-angled triangles in this matrix, according to your rules. Label the three points A, B, C. You can check if these form a triangle by iterating from row[A] to row[B], then from col[B] to col[C] and then diagonally from row[C] to row[A] and checking to see if the distances are the same and if you get to the right positions. You can terminate this early, for example if B is 8 and A is 1, then you can tell you won't find it once you hit 11 on column 1.
For parallelograms a similar reasoning can be made. Label the 4 points A, B, C, D and remember to sort them ascendingly (remember, your points here are actually numbers). See if you can get from col[A] to col[B] on the same line, then from col[C] to col[D] on the same line and then diagonally or vertically-down from row[A] to row[C] and then (in the same direction you went the previous diagonal!) from row[B] to row[D].
Hexagons are also have a specific format you must test for. Here's how hexagons look like in this representation:
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
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
You can notice that every two pairs of points share the same column, and that the horizontal distance between the two middle points is twice the vertical distance between any two points and also twice the horizontal distance between any other two points.
You will also want to consider rotations, so you'll need to do more tests for each case.
You don't even really need the row and col arrays unless you plan on computing them efficiently. Just walk over your matrix until you identify the first point in sorted order and try to get to the others while following each of the rules.
Not exactly a nice way, but you will only need a 256x256 matrix for this, so while this does result in quite a lot of code, it's pretty efficient. I hope I made myself clear, if not please say what isn't clear. Anyway, maybe someone else will post a better solution, so wait a while longer if you can..

Resources